Blog Stats
  • Posts - 7
  • Articles - 0
  • Comments - 1
  • Trackbacks - 0

 

Sunday, November 15, 2009

Fairfield CT - Fall 2009, CodeCamp Files Posted


I just posted the files from my Fairfield, CT CodeCamp presentation. Thanks to Mark Freedman and company for having me.

I’d also like to address a couple of questions I was asked, one during the presentation and one a couple of hours later.

 

1. Does the C# compiler duplicate field initializer code?

Yes, it does; but that’s not a problem. I added two overloads of the Constructors.ComplexInitialization.ComplexInitializationBase constructor to illustrate. The two overloads have the signatures (string) and (). When you chain them together: (string, string) => (string) => (), only the no-parameter constructor (), gets the field initialization logic. If you unchain them so both the (string) constructor and the () call the base constructor (System.object.ctor), then both get the field initialization logic. Apparently, the C# compiler only adds field initialization logic to constructors which directly call a base constructor, guaranteeing that while the code gets duplicated it only ever runs once for any given object.

2. Do object initializers work with properties

Yes. They work with both public properties and fields.

Later!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
 

 

Copyright © NedsNotes