Example #1
0
 // UseTheDel -- A “workhorse” method that takes a MyDelType delegate
 //    argument and invokes the delegate. arg is a string I want to pass
 //    to the delegate invocation.
 private static void UseTheDel(MyDelType del, string arg)
 {
     if (del == null) return; // Don't invoke a null delegate!
     // Here's where you invoke the delegate.
     // What's written here? A number representing the length of arg.
     Console.WriteLine("UseTheDel writes {0}", del(arg));
 }
Example #2
0
 // UseTheDel -- A workhorse method that takes a MyDelType delegate
 // argument and invokes the delegate; arg is a string to pass to the
 // delegate invocation
 private static void UseTheDel(MyDelType del, string arg)
 {
     if (del == null)
     {
         return;               // Don't invoke a null delegate
     }
     // Here's where the delegate is invoked
     Console.WriteLine("UseTheDel writes {0}", del(arg));
 }
Example #3
0
 // UseTheDel - A "workhorse" method that takes a MyDelType delegate
 //    argument and invokes the delegate. name is a string I want to pass
 //    to the delegate invocation.
 private static void UseTheDel(MyDelType del, string arg)
 {
     if (del == null)
     {
         return;        // Don't invoke a null delegate!
     }
     // Here's where we invoke the delegate.
     // What's written here? A number representing the length of name.
     Console.WriteLine("UseTheDel writes {0}", del(arg));
 }
Example #4
0
        public static void Main(string[] args)
        {
            // Create a delegate instance pointing to the CallBackMethod below;
            // note that the callback method is static, so you can prefix the
            // name with the class name, Program
            MyDelType del = new MyDelType(Program.CallBackMethod);

            // Call a method that will invoke the delegate
            UseTheDel(del, "hello");
        }
Example #5
0
 // Inside class or inside namespace
 static void Main(string[] args)
 {
     // Create a delegate instance pointing to the CallBackMethod below.
     // Note that the callback method is static, so you prefix the name
     // with the class name, Program.
     MyDelType del = new MyDelType(Program.CallBackMethod);
     // Call a method that will invoke the delegate.
     UseTheDel(del, "hello");
     // Wait for user to acknowledge results.
     Console.WriteLine("Press Enter to terminate...");
     Console.Read();
 }
Example #6
0
        delegate int MyDelType(string name); // ... or here, nested in the class.

        static void Main(string[] args)
        {
            // Create a delegate instance pointing to the CallBackMethod below.
            // Note that the callback method is static, so we prefix the name
            // with the class name, Program.
            MyDelType del = new MyDelType(Program.CallBackMethod);

            // Call a method that will invoke the delegate.
            UseTheDel(del, "hello");

            // Wait for user to acknowledge results.
            Console.WriteLine("Press Enter to terminate...");
            Console.Read();
        }