March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System; namespace Samples { public delegate string MyDelegate(string s); public class MyClass { public static string StaticMethod(string s) { Console.WriteLine("StaticMethod(\"{0}\")", s); return(s.ToUpper()); } public string InstanceMethod(string s) { Console.WriteLine("InstanceMethod(\"{0}\")", s); return(s.ToLower()); } } public class DelegateSample { public static void Main() { MyClass m = new MyClass(); MyDelegate s = new MyDelegate(MyClass.StaticMethod); MyDelegate i = new MyDelegate(m.InstanceMethod); Console.WriteLine("Method is {0}", s.Method); Console.WriteLine("Method is {0}", i.Method); Console.WriteLine("Returns: {0}", s("Call 1")); Console.WriteLine("Returns: {0}", i("Call 2")); MyDelegate d = (MyDelegate) Delegate.Combine(s, ...Read now
Unlock full access