Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Property Get Runs When Class Instantiated
Message
From
09/04/2009 17:49:53
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01394040
Message ID:
01394070
Views:
43
>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.

Now I am lost, still trying to figure that out.
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform