Example #1
0
        public static void AltaMetoda()
        {
            AbstractObserver afisaj = new Afisaj2();
            //MeteoStation.Instance.Run();
            var             del = new ExamplesEventsAndDelegates();
            AndreisDelegate ad1 = del.RunMultipleTimes;
            AndreisDelegate ad2 = AfisareNumar;

            Bum += ad1;
            Bum += ad2;
            ad1(2);
            ad2(4);
            ad2.Invoke(8);
            var i = 0;

            while (i < 3)
            {
                Console.WriteLine("introdu ceva");
                var ceva = Console.ReadLine();
                if (ceva == "Bum")
                {
                    if (Bum != null)
                    {
                        Bum.Invoke(i);
                    }
                    Console.WriteLine("Am invocat Bum ({0})", i);
                    i++;
                }
            }
            Console.WriteLine("gata while-ul");
        }
Example #2
0
        public static void Main(string[] args)
        {
            // exemplu metoda anonima
            Sum2 SumaMea = (int a, int b) => { return(a + b); };

            Console.WriteLine(SumaMea(3, 7));

            Multiply MultiplyGeo = (int a, int b, int c) => { return(a * b * c); };

            Console.WriteLine(MultiplyGeo(23, 11, 10));


            ExamplesEventsAndDelegates.AltaMetoda();
            Console.ReadLine();
            var r = new Random();
            int i = 0;

            while (true)
            {
                if ((i % 500) == r.Next(500))
                {
                    if (Xevent != null)
                    {
                        Xevent.Invoke(r.Next(10) + 1);
                    }
                }
                else if (i / 2 == r.Next(1000))
                {
                    if (Xevent2 != null)
                    {
                        Xevent2.Invoke(new ExampleEvent(), new EventArgs());
                    }
                }
                //else
                //{
                //    Xevent2.Invoke(new ExampleEvent(), new AndreisArgs(4.67));
                //}
                i++;
            }
        }