Answer Posted / dotnet user
using System;
// Declare delegate -- defines required signature:
delegate void SampleDelegate(string message);
class MainClass
{
// Regular method that matches signature:
static void SampleDelegateMethod(string message)
{
Console.WriteLine(message);
}
static void Main()
{
// Instantiate delegate with named method:
SampleDelegate d1 = SampleDelegateMethod;
// Instantiate delegate with anonymous method:
SampleDelegate d2 = delegate(string message)
{
Console.WriteLine(message);
};
// Invoke delegate d1:
d1("Hello");
// Invoke delegate d2:
d2(" World");
}
}
Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
How can we set the class to be inherited, but prevent the method from being over-ridden?
Is c# an open source?
i want o/p 011242110 in c# code.
What is the difference between ienumerable and iqueryable?
What do you know about WM_CHAR message?
What is parameters in c#?
Where are value types stored in c#?
What is ilist c#?
How to prevent the error while updating ui control from another thread?
What is a event in c#?
What does console readline do?
What are access modifiers used for?
How can I create a process that is running a supplied native executable (e.g., Cmd.exe)?
What is inline function in c#?
What does exclamation mark mean in access query?