C# FAQ: How would I create a Delegate or MulticastDelegate?

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

How would I create a Delegate or MulticastDelegate?

In order to declare a delegate, most programming languages require the programmer to specify both an object reference and a method to invoke. C# requires only a single parameter—the method address—to declare a delegate. C# infers the other pieces of information.

Here is an example:

using System.Threading;
 
ThreadStart: AClass MyClass = new AClass();
 
ThreadStart aDelegate = new ThreadStart (MyClass.aMethod);

Thus, delegates can invoke either instance methods or static class methods using a single syntax.

See also



Personal tools