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
Explain how many types of exception handlers are there in .net?
What is private void in c#?
Why attributes are used in c#?
What are most desktop applications written in?
How many digits is a 32 bit number?
What is the major difference between a custom control and user control?
What do you understand by 'access specifiers' in C#?
What is code verification?
Name any three ways to pass parameters to a method in c#?
What are collection classes?
Are c# destructors the same as c++ destructors?
What is an assembly qualified name
In which way a two-dimensional array declared in C#?
Explain the role of Garbage collector and its generations?
Is php easier than c#?