J
Joel
Is it true that if we don't specify a default constructor for
our class, then the C# compiler provides us with its own
that zeroes (or assigns default values) to the data members?
I wrote a no-parameter constructor for my class with an
empty function body. I then instantiated an object and tried
printing its values, amazingly the members were already initialized.
But how is this possible if I have not included any code for doing
so. The compiler obviously hasn't generated a constructor for
initialization because I have my own constructor (without any params).
The same thing happens when I write a constructor with parameters,
in this case, again, C# does not provide a default constructor but
yet the values are get initialized.
I tried using ILDASM to see what was going on, .. and System.Object's
constructor was being called at the beginning of my constructor's
body.
This was the only code that the compiler had generated.
Is it System.Object's constructor then that does the work of
initializing
the members. This doesn't make much sense because how can base class's
constructor get access to derived class's members!
Thanks for any help,
~ Joel
our class, then the C# compiler provides us with its own
that zeroes (or assigns default values) to the data members?
I wrote a no-parameter constructor for my class with an
empty function body. I then instantiated an object and tried
printing its values, amazingly the members were already initialized.
But how is this possible if I have not included any code for doing
so. The compiler obviously hasn't generated a constructor for
initialization because I have my own constructor (without any params).
The same thing happens when I write a constructor with parameters,
in this case, again, C# does not provide a default constructor but
yet the values are get initialized.
I tried using ILDASM to see what was going on, .. and System.Object's
constructor was being called at the beginning of my constructor's
body.
This was the only code that the compiler had generated.
Is it System.Object's constructor then that does the work of
initializing
the members. This doesn't make much sense because how can base class's
constructor get access to derived class's members!
Thanks for any help,
~ Joel