Re: constructors/default values
Peter Osucha <[email protected]> Thu, 11 Jan 2007 11:30:46 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Thanks all for the additional comments. Peter > -----Original Message----- > From: Discussion relating to the specifics of the C# and > Managed C++ languages [mailto:[email protected]] > On Behalf Of Bart De Smet [MVP] > Sent: Thursday, January 11, 2007 11:23 AM > To: [email protected] > Subject: Re: [DOTNET-CX] constructors/default values > > 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 DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com