Re: constructors/default values
"Bart De Smet [MVP]" <[email protected]> Thu, 11 Jan 2007 17:23:05 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <013b01c7359c$c5fef820$51fce860$@net> |
Indeed, as I pointed out on my blog in the latest C# Quiz: http://community.bartdesmet.net/blogs/bart/archive/2007/01/03/C_2300_-Quiz-_ 2D00_-Field-initialization.aspx http://community.bartdesmet.net/blogs/bart/archive/2007/01/04/C_2300_-Quiz-_ 2D00_-Field-initialization-_2800_cont_2700_d_2900_.aspx http://community.bartdesmet.net/blogs/bart/archive/2007/01/08/Answers-to-C_2 300_-Quiz-_2D00_-Field-initialization.aspx The only caveat is the different order of field initialization which can yield different results as demonstrated in the latest post. -Bart -----Original Message----- From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Richard Blewett Sent: donderdag 11 januari 2007 16:54 To: [email protected] Subject: Re: [DOTNET-CX] constructors/default values 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 =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com