"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi
a simple question about the meaning of "+=" in C#.
What does something like this mean:
this.TextBox1.TextChanged += new
System.EventHandler(this.TextBox1_TextChanged);
the += operator itself, consdiering the code x += y, x = x + y; That is it
adds the left side to the right side and assigns the result to the left.
In respect to events it indeed does attach a delegate to an event via an add
function. Its behaviour isn't exactly like the preceding += operator in that
it doesn't actually assign anything, it just calls the add method.
As a piece of minuta, you can also write events in the following form
event EventHandler TextChanged
{
add
{
//combine delegates
}
remove
{
//remove delegate from delegate list
}
}
The language has a simple way of expressing events when you do not need
special code in these accessors