Professional Documents
Culture Documents
Contents
What is Delegate ?
Types of Delegate.
Syntax.
characteristics.
Code Explanation.
Conclusion.
What Is Delegate ?
Instantiation
Invocation
Code for Single cast Delegate
using System;
namespace BasicDelegate
{
public delegate void SimpleDelegate(); // Declaration
class TestDelegate
{
public static void MyFunc()
{
Console.WriteLine("I was called by delegate ...");
}
public static void Main()
{
// Instantiation
SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc);
simpleDelegate(); // Invocation
}
}
}
Code for Multi cast Delegate
using System;
using System.Collections.Generic;
using System.Text;
namespace delegates
{
delegate void methodInvoker();
class Program
{
Program()
{
methodInvoker m = null;
m += new methodInvoker(Food);
m += new methodInvoker(Good);
m();
}
Condt:-
void Food()
{
Console.WriteLine("Hi I am Food ");
}
void Good()
{
Console.WriteLine("Hi I am Good ");