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
What is decimal in c#?
How to move to a state-related codebase?
What is the advantage of generics in c#?
What is mvc firstordefault?
When do we generally use destructors to release resources?
What is desktop example?
What is int16?
Can I do things in il that I can't do in c#?
What are partial types in c#?
What is the and operator in c#?
What is a framework in c#?
In gridview in editmode if we want to display information in one combobox based on
What is serialization in unity?
Does the variables of a private class-level inherited?
What Is An Interface Class?