Dear Friends ,
Any one can tell me the Delegate ?
want simple project or example to understand.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jun 28, 2012, 3:10 AM
A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.
Delegate is a type which holds the method(s) reference in an object. It is also referred to as a type safe function pointer.
public delegate int del_add(int a,int b);
static int fn_Add(int val1,int val2)
{
return val1+val2;
}
del_add delObj = new del_add(fn_Add);
Console.Write("Please Enter Values");
int v1 = Int32.Parse(Console.ReadLine());
int v2 = Int32.Parse(Console.ReadLine());
//use a delegate for processing
int res = delObj(v1,v2);
Console.WriteLine ("Result :"+res);
Console.ReadLine();
hope this will help you.