C
C#

help

what is this operation?

Tthieved2/18/2023
discord.MessageCreated += async (s, e) =>
discord.MessageCreated += async (s, e) =>
context:
Tthieved2/18/2023
im learning C# i know what += but why is it used like this in C#?
Mmtreit2/18/2023
That's an event You are adding an event handler to the event
Mmtreit2/18/2023
Events - C# Programming Guide
Learn about events. Events enable a class or object to notify other classes or objects when something of interest occurs.
Tthieved2/18/2023
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' ?
Mmtreit2/18/2023
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
Tthieved2/18/2023
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
public event AsyncEventHandler<DiscordClient, ReadyEventArgs> Ready
{
add => this._ready.Register(value);
remove => this._ready.Unregister(value);
}
public event AsyncEventHandler<DiscordClient, ReadyEventArgs> Ready
{
add => this._ready.Register(value);
remove => this._ready.Unregister(value);
}
so add is called when an event is added? i sorta understand wait i do
Rrotor_2/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?
Tthieved2/18/2023
new DiscordConfiguration() {
Token = Environment.GetEnvironmentVariable("DISCORDTOKEN"),
TokenType = TokenType.Bot
}
new DiscordConfiguration() {
Token = Environment.GetEnvironmentVariable("DISCORDTOKEN"),
TokenType = TokenType.Bot
}
sorry to ask another question but how does this work ? why isnt the object passed inside the class parameters ?
Rrotor_2/18/2023
It's a limitation of the library - honestly that should be passed in the constructor But like moles says there's a workaround
Tthieved2/18/2023
couldnt they pass an object? lol
Rrotor_2/18/2023
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!
Tthieved2/18/2023
omg C# and the extension for it on VSCODE has such good reference tracking
Tthieved2/18/2023
Tthieved2/18/2023
anyways, thank you sm @implicit electron ❤️

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ deployment error MAUI new projectHello guys! I created a new MAUI project and downloaded the emulator in VS Studio, but as you see, discord librarieswhich is better: `Discord.Net` or `DShardPlus` in your opinion?❔ need help setting up childForms | WinFormswhere can i get help with some winform stuff please, beginner dev just tryna learn some basic c#, imnew to C#, looking for a compiler?i'm coming from javascript and lua what's a good compiler for C#? i'm looking to write C# with `Vis❔ How to handle DNS-IP Changes while use of static HttpClient in v4.8 ?There is SocketsHttpHandler overload available in netcore2.1 but how do I handle dns-ip changes in f❔ How to use the visual studio community 2022 integrated terminal instead of windows terminal?I want to display my console application code output into the visual studio community 2022 integrateWriting and Reading binary files not workingIm making a game in windows forms for school and im making a register and login screen where i make It's working fine but the error is 'Input string was not in a correct format.'Can anyone help me here i'll post the error❔ Get an entity with Sql data clientHi, Im trying to read some data with the sql data client and Im stuck. The data looks like this: I❔ How do toggle top level statements?There's no mentions of this on google. How do you enable/disable this in an existing project?❔ Error when starting bothello❔ How can the guid claim out of the http contextHere is my token information and I use this code to get the guid but nothing return ```cs var guid =Calling Buildserviceprovider from application code results in additional copy of singleston servicesGreetings, I am currently working on a very old .NET 1.1 core project in .NET 6 and I saw a warnin✅ Accessing the appsettings.json that resides in a ASP.NET Core 6 project from another projectDo I need to always pass that down as a constructor or is there any other way to do it. I need the d✅ Help me to understand this questionPls help me to sovle this problem (assignment 5)❔ Class method construction using lambda?I was looking at some Avalonia code and I noticed this code internal class Database { ✅ Two symbols not resolvedI have two errors saying "symbol not resolved" on my code. All the methods here are inside of the sa❔ ✅ Help getting remote launch to perform task (display off)I've got an application that just turns off a monitor, nothing super complicated about it: ```cs int❔ Issues with for and foreachIm working on a school project and im having some issues with for and foreach, this is my project: U❔ Difference between these variantsI'm learning c# right now and I saw something as ArrayList myList = new ArrayList(); IList myList =