❔ Delegates and events
I'm trying to understand what these are, but I'm struggling a lot.
I remember working with events when I was making a discord bot, but that was with discord ruby and discord py.
Can someone help me understand this better? A simple analogy would be great since that's how I understand things best ><
10 Replies
Delegates are basically function pointers
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/
And events allow for easy pub-sub kind of communication
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/
Since you wanted analogies...
Delegates are methods you can store in a variable
Events are like subscribing to some thread on Discord, you get a notification when someone leaves a message
wait, you can store methods in is news to me
Yep
Angius#1586
REPL Result: Success
Console Output
Compile: 601.120ms | Execution: 31.858ms | React with ❌ to remove this embed.
Alternatively,
Angius#1586
REPL Result: Success
Console Output
Compile: 666.180ms | Execution: 82.434ms | React with ❌ to remove this embed.
And let's not forget anonymous functions either
Angius#1586
REPL Result: Success
Result: int
Compile: 508.075ms | Execution: 59.199ms | React with ❌ to remove this embed.
Ahh okay
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.