1 // Compiler options: -langversion:linq
2 // Uber-test for object and collection initialization
4 using System.Collections.Generic;
15 public Point P1 = new Point ();
16 public Point P2 = new Point ();
18 private class Rectangle
20 public Line Top = new Line ();
21 public Line Right = new Line ();
22 public Line Left = new Line ();
23 public Line Bottom = new Line ();
28 public string PhoneNumber;
29 public List<string> Books;
32 Books = new List<string> { "Tale of Two Cities", "Catcher in the Rye", "Great Gatsby" };
47 Thing thing1 = new Thing() { Number = 1, Name = "Bob" };
49 Line line = new Line { P1 = { X = 1, Y = 5 }, P2 = { X = 3, Y = 6 } };
50 if (line.P1.X != 1 || line.P1.Y != 5 || line.P2.X != 3 || line.P2.Y != 6)
53 Rectangle rectangle = new Rectangle () {
55 P1 = { X = 0, Y = 5 },
56 P2 = { X = 5, Y = 5 } },
58 P1 = { X = 0, Y = 0, },
59 P2 = { X = 5, Y = 0, }, },
61 P1 = { X = 5, Y = 5 },
62 P2 = { X = 5, Y = 0 } },
64 P1 = { X = 0, Y = 0, },
65 P2 = { X = 0, Y = 5 } } };
66 if (rectangle.Top.P1.X != 0 || rectangle.Bottom.P2.X != 5 || rectangle.Right.P2.Y != 0 || rectangle.Left.P1.Y != 0)
69 List<string> list = new List<string> (3) { "Foo", "Bar", "Baz" };
70 if (list[0] != "Foo" || list[1] != "Bar" || list[2] != "Baz")
73 Library library = new Library {
74 Name = "New York Public Library",
75 Books = { "Grapes of Wrath", "Dracula", },
76 PhoneNumber = "212-621-0626" };
77 if (library.Name != "New York Public Library" || library.PhoneNumber != "212-621-0626" ||
78 library.Books[0] != "Tale of Two Cities" ||
79 library.Books[1] != "Catcher in the Rye" ||
80 library.Books[2] != "Great Gatsby" ||
81 library.Books[3] != "Grapes of Wrath" ||
82 library.Books[4] != "Dracula")
86 Thing1 = new Thing { Number = 1, Name = "Wilber" },
87 Thing2 = new Thing() { Number = 2, Name = "Chris" } };
88 if (box.Thing1.Number != 1 || box.Thing1.Name != "Wilber" || box.Thing2.Number != 2 || box.Thing2.Name != "Chris")
91 Library library2 = new Library { Books = new List<string> { "The Hound of Baskerville", "Flatland", "The Origin of Species" } };
92 if (library2.Books[0] != "The Hound of Baskerville" ||
93 library2.Books[1] != "Flatland" ||
94 library2.Books[2] != "The Origin of Species")