InterviewSolution
| 1. |
How Do I Create A Delegate/multicastdelegate? |
|
Answer» C# requires only a single parameter for delegates: the METHOD address. Unlike other languages, where the programmer MUST specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name. For example, let's use System.Threading.ThreadStart: Foo MyFoo = NEW Foo(); ThreadStart del = new ThreadStart(MyFoo.Baz); This means that delegates can invoke STATIC class methods and instance methods with the exact same syntax! C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name. For example, let's use System.Threading.ThreadStart: Foo MyFoo = new Foo(); ThreadStart del = new ThreadStart(MyFoo.Baz); This means that delegates can invoke static class methods and instance methods with the exact same syntax! |
|