14 Replies
im learning C#
i know what
+=
but why is it used like this in C#?That's an event
You are adding an event handler to the event
Events - C# Programming Guide
Learn about events. Events enable a class or object to notify other classes or objects when something of interest occurs.
i know what an event is but
i meant
why is
+=
being used for that?
i come from javascript and lua
so +=
is for adding to strings, numbers, etc.
elaborate
is this one of those things like
'it is what it is'
?Yes, that syntax goes back to C# 1.0 over 20 years ago
They wanted events to be a first class thing and to support registering multiple event handlers for a single event
oh
okay well thats refreshing
i thought id have to discover some indepth explanation
because i like to know the why to things
but one question
what does an event look like for that to be the operation to subscribe to it?
right
like just calling
.on()
multiple times
right
ohhh
so thats a whole type
i made an event emitter in lua so
thats odd to have a whole type
for events
what is a delegate?
im new to C# lol
so add
is called when an event is added?
i sorta understand
wait i doSo C# delegates are composable? Do they feed the output of one into the input of the next or do they all just get run with the outputs discarded?
sorry to ask another question but how does this work ?
why isnt the object passed inside the class parameters ?
It's a limitation of the library - honestly that should be passed in the constructor
But like moles says there's a workaround
couldnt they pass an object?
lol
This is true, but I'd argue that the DiscordConfiguration won't do much without a token
Oooo I didn't know that thank you!
omg C# and the extension for it on VSCODE has such good reference tracking
anyways, thank you sm @implicit electron
❤️