Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nested Object Initializer Syntax
public class NestedInitializerExample
{
public void Init()
{
Rectangle rectangle = new Rectangle
{
P1 = { X = 0, Y = 1 },
P2 = { X = 2, Y = 3 }
};
}
}
public class Point
{
public int X { get; set; }
public int Y { get; set; }
}
public class Rectangle
{
public Rectangle()
{
P1 = new Point();
P2 = new Point();
}
public Point P1 { get; set; }
public Point P2 { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.