Dear Friends ,
Any one can tell me the Delegate ?
want simple project or example to understand.
Delegates
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 27, 2012, 11:10 PM EDT
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.