Simple usage

suggest change

Object initializers are handy when you need to create an object and set a couple of properties right away, but the available constructors are not sufficient. Say you have a class

public class Book
{
    public string Title { get; set; }
    public string Author { get; set; }

    // the rest of class definition
}

To initialize a new instance of the class with an initializer:

Book theBook = new Book { Title = "Don Quixote", Author = "Miguel de Cervantes" };

This is equivalent to

Book theBook = new Book();
theBook.Title = "Don Quixote";
theBook.Author = "Miguel de Cervantes";

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Object Initializers:
* Simple usage

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
45 Object Initializers
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script