Esempio n. 1
0
        static void Main(string[] args)
        {
            //PointToAddMethod pointAdd = Add();

            PointToAddMethod pointAdd = delegate(int a, int b)
            {
                return(a + b);
            };

            Console.WriteLine(pointAdd.Invoke(2, 3).ToString());
            Console.ReadKey();
        }
Esempio n. 2
0
        delegate int PointToAddMethod(int a, int b);//delegat

        static void Main(string[] args)
        {
            //RunKeyValuePair();
            //RunEnum();
            //RunAnthill();

            //Basebody bb = new Basebody();
            //bb.CreateBase("BaseBody - Name", 1.1f, 2.2f);

            //MilitaryBase aaa = new MilitaryBase(10);
            //aaa.CreateBase("MilitaryBase - Name", 9.9f, 10.10f);//100);

            //Basebody mbb = new MilitaryBase();
            //mbb.CreateBase("MilitaryBase - Name", 3.3f, 4.4f);

            //MilitaryBase bbm = new Basebody();//błąd

            /*
             * List<int> lista = new List<int>();
             *
             * Compare<int> compInt = new Compare<int>();
             * Console.WriteLine(compInt.CompareAnyType(2, 2));
             *
             * Compare<string> compStr = new Compare<string>();
             * Console.WriteLine(compStr.CompareAnyType("aa","aa"));
             *
             * MaxMin<float> comp = new MaxMin<float>();
             * Console.WriteLine(comp.Compare(2.2f,3.4f));
             */

            PointToAddMethod pointAdd = delegate(int a, int b)
            {
                return(a + b);
            };

            Console.WriteLine(pointAdd.Invoke(6, 4).ToString());
            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // delegat bez odwolania do metody
            //Stopwatch timerObj = new Stopwatch();

            //for (int i = 0; i < 10; i++)
            //{
            //    timerObj.Reset();
            //    timerObj.Start();

            //    for (int j = 0; j < 100000; j++)
            //    {
            //        PointToAddMethod pointAdd = delegate (int a, int b)
            //        {
            //            return a + b;
            //        };

            //        int c = pointAdd.Invoke(2, 3);
            //    }

            //    timerObj.Stop();
            //    Console.WriteLine(timerObj.ElapsedTicks.ToString());
            //}

            //tikirikitiki:
            //5161
            //4828
            //4489
            //4465
            //6828
            //6618
            //5815
            //4741
            //5068
            //5191

            // delegat z odwolaniem odwolania do metody


            Stopwatch timerObj = new Stopwatch();

            for (int i = 0; i < 10; i++)
            {
                timerObj.Reset();
                timerObj.Start();

                for (int j = 0; j < 100000; j++)
                {
                    PointToAddMethod pointAdd = Add;
                    int c = pointAdd.Invoke(2, 3);
                }

                timerObj.Stop();
                Console.WriteLine(timerObj.ElapsedTicks.ToString());
            }
            //tikirikitiki:
            //17373
            //7592
            //13468
            //10600
            //9611
            //11700
            //8011
            //6865
            //6737
            //6687

            Console.ReadKey();
        }