Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            TakeIntReturnIntDelegate method1 =
                delegate(int v) {
                return(v + 100);
            };

            DoSomethingWithDelegate(method1);

            DoSomethingWithDelegate(delegate(int x) { return(x / 2); });
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Doesn't work
            //TakeIntReturnIntDelegate del = Foo;

            // Hm... shouldn't work, but does :) -
            // Impossible to configure the C# compiler these days to NOT understand this.
            TakeIntReturnIntDelegate del = Square;

            // How it should have been in C# 1.0:
            del = new TakeIntReturnIntDelegate(Square);

            Console.WriteLine(del(13));

            // Delegates are types - do with them what you can do with other types.
            DoSomethingWithDelegate(del);
        }
Ejemplo n.º 3
0
 static void DoSomethingWithDelegate(TakeIntReturnIntDelegate del)
 {
     Console.WriteLine(del(5) + del(8));
 }
Ejemplo n.º 4
0
 static void DoSomething(TakeIntReturnIntDelegate function)
 {
     Console.WriteLine(function(10));
 }