Here is the difference between a delegate and an event.
Delegate:
public class VikramDel
{
public delegate void VikramExampleDelegate(int num1,string str1);
public VikramExampleDelegate VikramDeleageteCallback;
}
Event:
public class VikramEvent
{
public delegate void VikramExampleEvent(int num1,string str2);
public event VikramExampleEvent VikramEventCallback;
}
So syntax wise there is only one difference that we have to use the event keyword with the event.
So the question comes why do we have a keyword when the same work can be done without using it. But there is a reason for the existence of the keyword event. Lets take an example how would a client work with this class
VikramDel V = new VikramDel();
V.VikramDeleageteCallback +=new
VikramDel.VikramExampleDelegate (this.VikDelegate);
Here we are adding a new target to the invocation list of the delegate. The same code will work with the other class also without any problem
VikramEvent V = new VikramEvent();
V.VikramEventCallback + =new
VikramEvent.VikramExampleEvent(this.VikDelegate);
But consider a case where by instead of adding a new target to the invocation list of the delegate if I simply set a delegate to a new delegate (The difference is with the + sign being not there).
VikramDel V = new VikramDel();
V.VikramDeleageteCallback =new
VikramDel.VikramExampleDelegate (this.VikDelegate);
This code will work fine here but the same will not work with an event.
So what it means is that if we use the event keyword no client class can set it to null. This is very important. Multiple clients can use the same delegate. After multiple client have added a function to listen to the callback of the delegate. But now one of the client sets the delegate to null or uses the = sign to add a new call back. This means that the previous invocation list will not be used any more. Hence all the previous client will not get any of the callback even if they have registered for the call back.
Hence we can say that the even keyword adds a layer of protection on the instance of the delegate. The protection prevents any client to reset the delegate invocation list. They can only add or remove the target from the invocation list.