delegate new
In this chapter you will learn:
Using new operator with delegate
using System;//from j a v a 2s.c o m
class MainClass
{
delegate int MyDelegate(string s);
static void Main(string[] args)
{
MyDelegate Del1 = new MyDelegate(DoSomething);
MyDelegate Del2 = new MyDelegate(DoSomething2);
string MyString = "Hello World";
Del1(MyString);
Del2(MyString);
}
static int DoSomething(string s)
{
Console.WriteLine("DoSomething");
return 0;
}
static int DoSomething2(string s)
{
Console.WriteLine("DoSomething2");
return 0;
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » delegate, lambda, event