Understanding Initializers

You can use initializers to reduce the amount of work it takes to create a new instance of a class. For example, assume that you have a class that looks like Listing 20.2 (in C#) or like Listing 20.3 (in VB.NET).

Listing 20.2. LanguageChanges\App_Code\Product.cs

images

Listing 20.3. LanguageChanges\App_Code\Product.vb

images

images

The Product class has three public properties (declared by taking advantage of automatic properties in the ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.