One-Step Object Creation and Initialization in C# 3.0
You can also have embedded initialization in ScienceClass, but you will need to declare your ScienceClass a little differently, as shown below:
public class ScienceClass
{
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
public Student Student1
{
get
{
return s1;
}
set
{
s1 = value;
}
}
public Student Student2
{
get
{
return s2;
}
set
{
s2 = value;
}
}
public Student Student3
{
get
{
return s3;
}
set
{
s3 = value;
}
}
}
One-Step Object Creation and Initialization
Object initializers provide a new syntax to initialize the objects you create. This simple syntax combines object creation and initialization into a single step.
Download the Code
You download the source code for this article here.
About the Author
Vipul Patel is a Microsoft MVP (two years in a row) in Visual C# and currently works at Microsoft through Volt Information Sciences. He specializes in C# and deployment issues. You can reach him at Vipul_d_patel@hotmail.com.
0 Comments (click to add your comment)
Networking Solutions



Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
Discover how to start developing for the Android platform with this extensive guide, which provides a reference to the Android platform as well as a look at developing your first Android application. You'll explore the top 10 features for developers as well as learn design and development tips that go beyond the phone and target tablet development as well.