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
Name the method of servicebase class?
Explain About multi level and multiple inheritance how to achieve in .net
What does return do in unity?
What is data adapter in c#?
Define c# i/o classes?
Is there regular expression (regex) support available to c# developers?
What is eager loading in c#?
What is difference between the "throw" and "throw ex" in .net?
What is the advantage of singleton class?
What is streamreader/streamwriter class?
Can scriptable objects have methods?
What is use of a HashTable in .NET?
What is the xml document structure?
What is the use of flag in c#?
What is the different types of private assembly and shared assembly?