示例#1
0
        static void Main(string[] args)
        {
            /*var list = new ArrayList();//前者是装拆箱后者是泛型var list = new List<int>();
             * list.Add(44);
             * int il = (int)list[0];//前者是装拆箱后者是泛型int i1=list[0];
             * foreach (int i2 in list)
             * {
             *  Console.WriteLine(i2);
             * }*/
            /*var list1 = new LList();
             * list1.AddLast(2);
             * list1.AddLast(4);
             * list1.AddLast("6");
             *
             * foreach (int i in list1)
             * {
             *  Console.WriteLine(i);
             * }
             *
             * var list1 = new LList();
             * list1.AddLast(2);
             * list1.AddLast(4);
             * list1.AddLast("6");
             *
             * foreach (int i in list1)
             * {
             *  Console.WriteLine(i);
             * }
             *
             * var list2 = new LList<int>();
             * list2.AddLast(1);
             * list2.AddLast(3);
             * list2.AddLast(5);
             *
             * foreach (int i in list2)
             * {
             * Console.WriteLine(i);
             * }
             *
             * var list3 = new LList<string>();
             * list3.AddLast("2");
             * list3.AddLast("four");
             * list3.AddLast("foo");
             *
             * foreach (string s in list3)
             * {
             * Console.WriteLine(s);
             * }*/

            /*var dm = new DocumentManager<Document>();
             * dm.AddDocument(new Document("Title A", "Sample A"));
             * dm.AddDocument(new Document("Title B", "Sample B"));
             * dm.DispalyAllDocuments();
             * if(dm.IsDocumentAvailable)
             * {
             *  Document d = dm.GetDocument();
             *  Console.WriteLine(d.Content);
             * }*/

            StaticDemo <string> .x = 4;
            StaticDemo <int> .x    = 5;
            Console.WriteLine(StaticDemo <int> .x);

            var r = new Rectangle {
                Width = 5, Height = 2.5
            };

            Console.WriteLine(r.ToString());
//协变:把返回值赋予IIndex<Rectangle>类型的变量rectangle,因为协变,所以可以把值赋予IIndex<Shape>类型的变量
            IIndex <Rectangle> rectangles = RectangleCollection.GetRectangle();
            IIndex <Shape>     shapes     = rectangles;

            for (int i = 0; i < shapes.Count; i++)
            {
                Console.WriteLine(shapes[i]);
            }
//抗变:IDisplay<T>是抗变的,可以把结果赋予IDisplay<Rectangle>
            IDisplay <Shape>     shapeDisplay     = new ShapeDisplay();
            IDisplay <Rectangle> rectangleDisplay = shapeDisplay;

            rectangleDisplay.Show(rectangles[0]);

            var accounts = new List <Account>()
            {
                new Account("Christian", 1500),
                new Account("Stephanie", 2200),
                new Account("Angela", 1800),
                new Account("Matthias", 2400),
            };
            decimal amount = Algorithm.AccumulateSimple(accounts);

            Console.WriteLine(amount);

            //decimal Amount = Algorithm.Accumulate<Account>(accounts);
            //decimal Amount = Algorithm.Accumulate<Account, decimal>(accounts, (item, sum) => sum += item.Balance);

            var test = new MethodOverloads();

            test.Foo(33);
            test.Foo("abc");
            test.Bar(44);
        }
示例#2
0
 public static RectangleCollection GetRectangle()
 {
     return(coll ?? (coll = new RectangleCollection()));
 }