This is the order in which the C# compiler emits the instructions into the constructor in IL
Field initializers simply become statements in the constructor once compiled - the CLR has no notion of what they are. The C# compiler emits them into the constructor before it puts the call to the base constructor in, then it puts the derived constructor body.
It does this because if you call a virtual method from a base class constructor and that virtual method has been overridden in the derived class, the derived version will fire. Since the derived constructor body hasn't yet been run, running the field initializers gives the derived class some way of setting sensible values in its state before the base class constructor runs.
btw: IIRC VB.NET puts all derived class construction after the base class construction.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
Hi Jon,
Thanks for your information .. I had a confusion bcoz I am from VC++
background and so was thinking in that terms..
Is it only in the C# or all .Net languages support this functionality.
--
Regards
Dhananjaya R