using System;
namespace ConsoleApplication1
{
class Program
{
public delegate void Del(string message);
static void Main(string[] args)
{
// Instantiate the delegate.
Del handler = DelegateMethod;
// Call the delegate.
for (int i = 0; i < 9; i++)
{
handler("Hello World " + i.ToString());
}
Console.ReadKey();
}
// Create a method for a delegate.
public static void DelegateMethod(string message)
{
System.Console.WriteLine(message);
}
}
}
Result
Hello World 0
Hello World 1
Hello World 2
Hello World 3
Hello World 4
Hello World 5
Hello World 6
Hello World 7
Hello World 8
namespace ConsoleApplication1
{
class Program
{
public delegate void Del(string message);
static void Main(string[] args)
{
// Instantiate the delegate.
Del handler = DelegateMethod;
// Call the delegate.
for (int i = 0; i < 9; i++)
{
handler("Hello World " + i.ToString());
}
Console.ReadKey();
}
// Create a method for a delegate.
public static void DelegateMethod(string message)
{
System.Console.WriteLine(message);
}
}
}
Result
Hello World 0
Hello World 1
Hello World 2
Hello World 3
Hello World 4
Hello World 5
Hello World 6
Hello World 7
Hello World 8
No comments:
Post a Comment