Information Technology Reference
In-Depth Information
// Instance Initializers would go here.
object (); // Not legal, illustrative only.
commonConstructor(initialCount, "" );
}
public MyClass( int initialCount, string Name)
{
// Instance Initializers would go here.
object (); // Not legal, illustrative only.
commonConstructor(initialCount, Name);
}
private void commonConstructor( int count,
string name)
{
coll = (count > 0 ) ?
new List < ImportantData >(count) :
new List < ImportantData >();
this .name = name;
}
}
If you could write the construction code for the first version the way the
compiler sees it, you'd write this:
// Not legal, illustrates IL generated:
public class MyClass
{
private List < ImportantData > coll;
private string name;
public MyClass()
{
// No variable initializers here.
// Call the third constructor, shown below.
this ( 0 , "" ); // Not legal, illustrative only.
}
public MyClass( int initialCount)
{
// No variable initializers here.
Search WWH ::




Custom Search