Esempio n. 1
0
        static void Main(string[] args)
        {
            Dervied        d   = new Dervied();
            SampleDelegate fac = new SampleDelegate(d.Method);

            fac("TEST");
            AnonymousDelegate();
            PredicateFun();

            SortAndShowFiles("Sort by name:", delegate(FileInfo f1, FileInfo f2)
            {
                return(f1.Name.CompareTo(f2.Name));
            });

            Func <string> print = delegate()
            {
                return("");
            };

            Console.ReadLine();
        }
Esempio n. 2
0
        static void LogMouseEvent(Object obj, MouseEventArgs e)
        {
            Console.WriteLine("LogMouse");

            ThreadStart ts  = new ThreadStart(MyMethod);
            ThreadStart ts2 = MyMethod;
            Thread      t   = new Thread(ts2);

            t.Start();

            StreamFactory factory = GenerateSampleData;

            using (Stream stream = factory())
            {
                int data;
                while ((data = stream.ReadByte()) != -1)
                {
                    Console.WriteLine(data);
                }
            }

            //=======================
            EventHandler         handler    = new EventHandler(LogPlainEvent);
            KeyPressEventHandler keyHandler = new KeyPressEventHandler(handler);

            //==============
            Dervied        x   = new Dervied();
            SampleDelegate fac = new SampleDelegate(x.CandidateAction);

            fac("TEST!!");

            ActionMethod();
            //===============================
            List <int> intList = new List <int>();

            intList.Add(5);
            intList.Add(10);
            intList.Add(15);
            intList.Add(25);

            intList.ForEach(delegate(int n) {
                Console.WriteLine(Math.Sqrt(n));
            });

            //================
            Predicate <int> isEven = delegate(int xx) { return(xx % 2 == 0); };

            Console.WriteLine(isEven(10));

            //SortAndShowFiles("Sort by name:",delegate(FileInfo f1,FileInfo f2) { return f1.Name.CompareTo(f2.Name); });

            EnclosingMethod();
            CaptureVariable();

            Console.WriteLine("//=======================");
            MethodInvoker xxx = CreateDelegateInstace();

            xxx();
            xxx();

            InitCapturedVariable();
        }