Loading
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
Rajeesh MenothRank #118 · 18.4K reputationPosted Oct 11, 2015, 9:30 AM EDT
Ravi PatelRank #439 · 5.7K reputationPosted Oct 11, 2015, 8:50 PM EDT
Basically, events provide for a tightly coupled publish subscribe paradigm, while delegates provide for a much more loosely coupled design.
for more details
Nilesh JadavRank #109 · 20.3K reputationPosted Oct 11, 2015, 8:55 PM EDT
Delegate:
A delegate in C# is similar to a function pointer in C. A delegate object holds the reference of one or more methods. Delegate creation is the four steps process.A delegate object doesn't care about the class in which the function exists. There is only one restriction that the delegate signature and the function signature should be same otherwise delegate object can’t hold the reference of the method which doesn't have the same signature. Signature means return type and parameters.
Example
public class Math
{
public static int Add(int i, int j)
{
return i + j;
}
}
class DelegateAndEvent
{
//Delegate Declaration
public delegate int MathFunctions(int i, int j);
static void Main()
{
//Delegate object creation.
MathFunctions MathFun = null;
//Point the reference to the method.
MathFun += Math.Add;
// Invoke delegate.
int value = MathFun.Invoke(10, 20);
Console.WriteLine(value.ToString());
Console.ReadLine();
}
}
Events:
Event is a mechanism by which a class can send notification to its client. For example, you have an application to perform certain operation, if an operation is failed then the application send the notification to log file, printer, fax, email etc.
Events are declared using delegates. Without delegate, we can not create Events.
Read this Full Article that describes much more about Delegates and Events with enhanced example :
http://einterviewquestions.blogspot.in/2012/12/difference-between-delegate-and-events.html
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 11, 2015, 8:59 PM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 11, 2015, 10:55 PM EDT