123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace initInsertedTypes { class Program { static void Main(string[] args) { // modern way Rectangle r = new Rectangle() // { TopLeft = new Point() { X = 10, Y = 10 }, BottomRight = new Point() { X = 100, Y = 100 } }; // traditional way - more code )) Rectangle r2 = new Rectangle(); Point p1 = new Point(); p1.X = 10; p1.Y = 10; r2.TopLeft = p1; } } class Point { public int X { get; set; } public int Y { get; set; } public Point() { } public Point(int x, int y) { X = x; Y = y; } } class Rectangle { private Point topLeft = new Point(); private Point bottomRight = new Point(); public Point TopLeft { get { return topLeft; } set { topLeft = value; } } public Point BottomRight { get { return bottomRight; } set { bottomRight = value; } } public void Display() { } } } |