Re: constructors/default values

Richard Blewett <[email protected]> Thu, 11 Jan 2007 15:53:54 -0000
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <[email protected]>
I'm afraid this isn't accurate. This is only true if the variable is static.
There is no substantial difference between initializing a variable inline
(known as a field initializer) and putting it in the constructor. If you
look at the generated IL then the field initializer just becomes code in the
constructor anyway.

The one difference is where in the constructor the code goes - the field
initializers come first, then the call to the base class constructor then
the actual constructor body

Regards

Richard Blewett - DeveopMentor

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:[email protected]] On Behalf Of Bill Fellows
Sent: 11 January 2007 14:51
To: [email protected]
Subject: Re: [DOTNET-CX] constructors/default values

The bottom line is that by assigning a variable value in the variable
declaration line, it is assigned when the class itself is created, before
any instances exist.

Bill

On Tue, 2 Jan 2007 10:12:05 -0500, Peter Osucha
<[email protected]> wrote:

>What is the difference (practically) in assigning a variable value in the
>variable declaration line and in the constructor?
>
>Peter
>
>
>
>
>
>===================================
>This list is hosted by DevelopMentorR  http://www.develop.com
>
>View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com