示例#1
0
        public void Run()
        {
            var myGenericIntDelegate = new Incrementor <int>(IntIncrementor);
            var myGenericStrDelegate = new Incrementor <string>(StringIncrementor);
            var myGenericDelegate    = new Incrementor <long>(GenericIncrementor);

            myGenericIntDelegate.Invoke(1);
            myGenericStrDelegate.Invoke(1.ToString());
            myGenericDelegate.Invoke(1);

            var mySuperTypedDelegate = new SuperIncrementor <string>(SuperStringIncrementor);

            mySuperTypedDelegate.Invoke("22");

            Action <string> stringIncrementorAction = StringIncrementor;

            stringIncrementorAction("10");

            Func <string, string> genericLongFunc = SuperStringIncrementor;

            genericLongFunc("generic");

            Predicate <int> valueCheckerPredicate = i => i < 10;

            Console.WriteLine(valueCheckerPredicate.Invoke(10));

            valueCheckerPredicate += i => i % 2 == 0;
            Console.WriteLine(valueCheckerPredicate.Invoke(10));
        }