VB.NET implicitly instantiating objects
Posted on 2004-08-11
I have a class Application, which has a collection containing Applicants attached to it.
In the property for the collection, I have the following:
If _Applicants is Nothing then
_Applicants = new ObjectCollection
Now, when I create an Application, I don't make any sort of reference to the Applicant collection, and immediately after the Application is created, in the Quick Watch window I can see that _Applicants is still nothing. The problem starts in the loop below:
For each objApplicant in objApplication.Applicants
....do some stuff
If I set a break point on the "for each" line, then use the watch to check, _Applicants has been instantiated. However, because it hasn't gone through the property, the Applicants haven't been loaded and I never get inside the loop.
Is there anything I can do to stop .NET implicitly creating the Applicants collection, or force it to do so via the property?