C#
C#

help

Root Question Message

victory
victory2/18/2023
what is this operation?

discord.MessageCreated += async (s, e) =>


context:
victory
victory2/18/2023
im learning C#
victory
victory2/18/2023
i know what += but why is it used like this in C#?
mtreit
mtreit2/18/2023
That's an event
mtreit
mtreit2/18/2023
You are adding an event handler to the event
victory
victory2/18/2023
i know what an event is but
victory
victory2/18/2023
i meant
victory
victory2/18/2023
why is += being used for that?
victory
victory2/18/2023
i come from javascript and lua
victory
victory2/18/2023
so += is for adding to strings, numbers, etc.
Message Not Public

Sign In and Join Server To See

2/18/2023
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
elaborate
victory
victory2/18/2023
is this one of those things like
victory
victory2/18/2023
'it is what it is'
victory
victory2/18/2023
?
mtreit
mtreit2/18/2023
Yes, that syntax goes back to C# 1.0 over 20 years ago
mtreit
mtreit2/18/2023
They wanted events to be a first class thing and to support registering multiple event handlers for a single event
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
oh
victory
victory2/18/2023
okay well thats refreshing
victory
victory2/18/2023
i thought id have to discover some indepth explanation
victory
victory2/18/2023
because i like to know the why to things
victory
victory2/18/2023
but one question
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
what does an event look like for that to be the operation to subscribe to it?
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
right
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
like just calling .on() multiple times
victory
victory2/18/2023
right
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
ohhh
victory
victory2/18/2023
so thats a whole type
victory
victory2/18/2023
i made an event emitter in lua so
victory
victory2/18/2023
thats odd to have a whole type
victory
victory2/18/2023
for events
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
what is a delegate?
victory
victory2/18/2023
im new to C# lol
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
        public event AsyncEventHandler<DiscordClient, ReadyEventArgs> Ready
        {
            add => this._ready.Register(value);
            remove => this._ready.Unregister(value);
        }
victory
victory2/18/2023
so add is called when an event is added?
Message Not Public

Sign In and Join Server To See

2/18/2023
Message Not Public

Sign In and Join Server To See

2/18/2023
Message Not Public

Sign In and Join Server To See

2/18/2023
victory
victory2/18/2023
i sorta understand
victory
victory2/18/2023
wait i do
Rotor
Rotor2/18/2023
So 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?
Message Not Public

Sign In and Join Server To See

2/18/2023
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy