コード例 #1
0
        static void Main(string[] args)
        {
            //Generic Type definition
            var nowystos = new Stack <int>();

            nowystos.Push(1);
            nowystos.Push(50);
            Console.WriteLine(nowystos.Pop());

            Type a1 = typeof(A <>);
            Type a2 = typeof(A <,>);
            Type a3 = typeof(A <int, int>);

            Console.WriteLine(a2.GetGenericArguments().Count());

            Console.WriteLine("Generics with static fields");
            Console.WriteLine(++Test <int> .Count);    //1
            Console.WriteLine(++Test <int> .Count);    //2
            Console.WriteLine(++Test <object> .Count); //1
            Console.WriteLine(++Test <object> .Count); //2

            //Kowariancja z out
            Stact2 <Beer> Beeers = new Stact2 <Beer>();

            Beeers.Push(new Beer());
            IPopable <Beer>   Beers   = Beeers;
            IPopable <Animal> Animals = Beers;

            Console.WriteLine(Animals.Pop().GetType().FullName);

            //Kontrawariancja z in
            IPushable <Animal> Animalss = new Stact2 <Animal>();
            IPushable <Beer>   Beerss   = Animalss;

            Beerss.Push(new Beer());
            Console.WriteLine(Beerss.GetType().FullName);

            //Delegates
            int[] valuesInts = { 1, 2, 3 };
            Transform(valuesInts, Square);
            for (int i = 0; i < valuesInts.Length; i++)
            {
                Console.WriteLine(valuesInts[i]);
            }
            Transformer <double> t2 = Square;

            Console.WriteLine(t2.Invoke(3.3));

            int[] valuesInts2 = { 1, 2, 3 };
            Transform2 <int>(valuesInts2, Square);
            for (int i = 0; i < valuesInts2.Length; i++)
            {
                Console.WriteLine(valuesInts2[i]);
            }

            Func <double, double> squareFunc = x =>
            {
                return(x * x);
            };
            Func <double, double, double> multiplyFunc = (x, y) =>
            {
                return(x * y);
            };
            Action <int> actionX = (x) =>
            {
                Console.WriteLine("Acion has fired with value of " + x);
            };

            D1 d1 = WriteSmth;
            D2 d2;

            d2 = new D2(d1);
            d2.Invoke();

            Console.WriteLine(squareFunc(5.5));
            Console.WriteLine(multiplyFunc(5.5, 5.5));

            //Events

            List <Stock> Stocks = new List <Stock>
            {
                new Stock("X1")
                {
                    Price = 22,
                },
                new Stock("X2")
                {
                    Price = 23
                }
            };

            foreach (var stock in Stocks)
            {
                stock.PriceChanged += StockHasChanged;
            }
            Stocks[0].Price = 2;


            //LING
            var linqExamples           = new LinqExamples();
            var dymicFunctionsExamples = new Generics.dynamic.Dynamic();
            var asyncExamples          = new AsyncExamples();
            var adoNetExamples         = new AdoNetExample();



            Console.ReadKey();
        }