August 2008
Intermediate to advanced
197 pages
3h 23m
English
The code in Listing 1-1 used another C# 3.0 feature called object initialization expressions:
List<Person> people = new List<Person> {
new Person() { ID = 1,
IDRole = 1,
LastName = "Anderson",
FirstName = "Brad"},
new Person() { ID = 2,
IDRole = 2,
LastName = "Gray",
FirstName = "Tom"}
};
Just like an array initializer, an object initialization expression allows us to initialize a new object without calling its constructor and without setting its properties. Let's look at an example in Listing 1-6.
// The standard object creation and initialization Person p1 = new Person(); p1. FirstName = "Brad"; p1.LastName = "Anderson"; ObjectDumper.Write(p1); // ... |
Read now
Unlock full access