How to

use object initializers

Published: 25. November 2011 | Updated: 25. November 2011
License: Microsoft Public License (MS-PL)
Categories: Framework
Tags: C#
Was this snippet helpful for you? YESYES / NONO

Example class

public class MyClass
{
    public int A { get; set; }

    public string B { get; set; }
}

Code

// initialize properties
var obj = new MyClass { A = 1, B = "b" };
Send us feedback about this snippet »



Related Snippets: