4
Reply

Constructor question, reference problem

Miodrag

Miodrag

Sep 18 2008 5:52 AM
2.1k
Hello I have two questions. 1. Is it possible to call base constructor in the body of the current constructor? I want code like this: class MyClass { public MyClass() { // some code here base(); } } 2. I don't understand this code. I have an object that returns reference to the DataTable it contains. I am wondering how come that in following code t variable remains valid: void MyClass() { DataTable t; void SomeFunc(){ using ( ObjectWithTable owt = new ObjectWithTable() ) { t = owt.Table; } } } The GC will free the owt as soon as it exits the using statement, but I can still access its table over t. Thanks.

Answers (4)