Example #1
0
        static void Main(string[] args)
        {
            MyDelegate d = new MyDelegate((x) => Console.WriteLine(x));

            d("Hello World!");

            var d2 = new MyDelegate2((x) => x + 0.1);

            Console.WriteLine(d2(1));

            var d3 = new MyDelegate3(calculate_square);

            Console.WriteLine(d3.Invoke(3));

            var         d4 = new MyDelegate4(Method1);
            var         d5 = new MyDelegate4(Method2);
            MyDelegate4 d6 = d4 + d5;

            d6.Invoke();

            Func <int, int> get_square = calculate_square;

            Console.WriteLine(get_square(5));

            Action myDelegateMethod1 = Method1;

            myDelegateMethod1.Invoke();

            Action myDelegateDemo = () =>
            {
                Console.WriteLine("hi");
            };

            myDelegateDemo.Invoke();

            List <int> myIntList = new List <int> {
                1, 3, 5, 99, 100, 200, 500, 999
            };
            var myBigNubmers = myIntList.Where(IsBigNumber);

            Console.WriteLine(String.Join(",", myBigNubmers.Select(x => x.ToString())));

            List <int> excludeList = Exclude(myIntList, IsBigNumber);

            Console.WriteLine(String.Join(",", excludeList.Select(x => x.ToString())));

            IEnumerable <Person> people = new List <Person>()
            {
                new Person("fang", "chen", new DateTime(1982, 7, 6)),
                new Person("fang2", "chen2", new DateTime(1982, 7, 5)),
                new Person("fang3", "chen3", new DateTime(1982, 7, 4))
            };
            var newOrderedPeople = people.OrderBy(GetSortFunction(SortOrder.BirthDate));

            Console.WriteLine(String.Join("; ", newOrderedPeople.Select(p => p.ToString())));
        }
Example #2
0
        static void Main(string[] args)
        {
            Functional  functional  = new Functional(Method);
            MyDelegate3 myDelegate3 = functional.Invoke(new MyDelegate1(Method1), new MyDelegate2(Method2));

            //оно впихнуло анонимный метод в myDelegate3, который возвратит Hello World
            Console.WriteLine(myDelegate3.Invoke());

            //Delay
            Console.ReadKey();
        }