Wednesday, April 23, 2008

3.0 Object Initializers

Simply the process to initialize:



public class Bunny
{
public string Name;
public bool LikeCarrots;
public Bunny(string n)
{
this.Name = n;
}
}



Bunny b1 = new Bunny { Name = "stupid", LikeCarrots = false };
Bunny b2 = new Bunny("foo") { LikeCarrots = true };

No comments: