Skip to content

Instantly share code, notes, and snippets.

@dariusz-wozniak
Created October 12, 2014 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariusz-wozniak/3cc70aa649761d6a0076 to your computer and use it in GitHub Desktop.
Save dariusz-wozniak/3cc70aa649761d6a0076 to your computer and use it in GitHub Desktop.
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