I'm working in .net 3.5. I have a class "A" which has a stack and a getter property which, when called, removes the first item in the stack and retrieves the next one.
After initializing the class, I saw that the getter works without being called, and removes the top item in the stack, thus giving me bad results. A breakpoint in the getter did not show anyone passing through it.
When I change the property to a function, the stack is returned ok.
I'd be happy if someone could explain why is that.
Here is the simplified class:
public class A
{
private Stack<string> Urls;
public A(string title, string[] array)
{
Urls = new Stack<string>();
foreach (string s in array)
{
Urls.Push(s);
}
}
public string Url
{
get { return Urls.Peek(); }
}
public string NextUrl
{
get{
if (Urls.Count > 1)
{ Urls.Pop(); }
return Urls.Peek();
};
}
}
Thanks!