C# - Events. Why would I use them?

02/24/2014 12:38 Y u k i#1
I know this is sorta offtopic, but the general programming section is mainly german speaking - dont get me wrong, thats my native language, but when it comes to programming I dont even understand exceptions in my language..

My question is rather simple I guess:

Why would i ever your events?

I see no point for them to exist. I can do the same thing on variables by an simple get{} set{} accessor, and within methods, i can simply call another method.

Ofc there might be that thing with subscribing to multiple handlers and unsubscribing, but i can simply do a boolean check within my get / set. Unless im doing like 5 different things in them based on some condition, i´d have to write more code using events.

I hope someone could explain the benefits to me. I´ve been on codeproject and msdn for some time now but cant find a reason to use them. I know how to define them, how to implement them but i fail to understand the point of their existence.

Thanks in advance!
02/24/2014 14:37 SteveRambo#2
[Only registered and activated users can see links. Click Here To Register...]
02/24/2014 15:08 hadeset#3
I am not going to go into details, but how I see it is, that they are good at keeping layers detachable from each other.
02/24/2014 17:15 Super Aids#4
[Only registered and activated users can see links. Click Here To Register...]

And

[Only registered and activated users can see links. Click Here To Register...]
02/25/2014 08:11 Y u k i#5
Okay, I read all of your Posts/Links and came to the conclusion, that there is no point for me to use them yet. I simply dont have any scenarios where it would benefit me enough to consider it.

Imho, delegates and events just kill readablilty.
02/25/2014 08:57 Spirited#6
Delegates can be very helpful. In fact, you'll see me using them in Project Phoenix's socket system. I use delegates as a replacement for pure virtual functions. Then, inheritance comes into play in initializing those delegates. Just one design idea, but there's a lot of uses for delegates. You can use delegates to point to functions outside a tree or other data structure, or store entire functions to memory in data structures using events. There really is a lot you can do with them.