Destructing an object
Hi,
I have this main "test" code,
{
Firm f = new Firm(0.3f);
Consumer c = new Consumer(1,f);
Console.WriteLine("First Test {0}",(c.isNull() ? "FAIL" : "OK"));
f = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("Second Test {0}",(c.isNull() ? "OK" : "FAIL"));
}
The Consumer constructor do this...
public Consumer(int pId, Firm pFirm)
{
Id = pId;
myFirm = new Firm(0f);
myFirm = pFirm;
}
where myFirm is defined as "private Firm myFirm;"
and the isNull() method is like this,
public bool isNull()
{
return (myFirm==null);
}
When I run the test... y obtain,
First Test OK
Second Test FAIL
Can anyone explain to me why the second test Fail?
I understand (well I think so) that the object "f" is passed to the constructor by reference.
Thanks in advance!!!!

kovanRank #1,453 · 1.1K reputationPosted Jul 19, 2004, 7:59 AM EDT
netgesid3 reputationPosted Jul 19, 2004, 8:03 AM EDT
david 0Rank #8,108 · 228 reputationPosted Jul 20, 2004, 3:19 AM EDT