Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Property Get Runs When Class Instantiated
Message
 
To
09/04/2009 17:01:43
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01394040
Message ID:
01394061
Views:
45
BY GOD I FOUND IT!!! I just don't understand it!

I changed the _LoadData to this:
private void _LoadClients()
{
    _colClients.Clear();

    MessageBox.Show(_colClients.Count.ToString());              // I addd this

    csClients oClients = new csClients();
    oClients.LoadData(this.iRecordId);
    _colClients = oClients.colData;
}
I instantiated the class with a breakpoint on this line:
csCompany oCompany = new csCompany();
If I press F10 to step over, the MessageBox never fires, so I assume the method is not being called. But when I hover the mouse over oCompany and expand it, the MessageBox fires, so I'm concluding that the property GET is being run during debug, which is calling _LoadData.


I tested this with:
class csCompany
{
    public int iCount = 0;

    private ArrayList _colClients = new ArrayList();
    public ArrayList colClients
    {
        get
        {
            if (_colClients.Count == 0)
            {
                _LoadClients();
            }
            return _colClients;
        }
    }

    private void _LoadClients()
    {
        iCount = 100;
    }
}
Then, I ran this:
namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            csCompany oCompany = new csCompany();
            int x = oCompany.iCount;    // Returns 0;
        }
    }
}
If I step over the instantiation, x is 0. I, But, if after the instantiation I hover the mouse over the variable, x is then 100.

I learned something new today.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform