C#C
C#10mo ago
Moebytes

class constructor in c#

My editor wants to convert the following code
public class Ping : ICommand {
    private readonly DiscordClient discord;
    private readonly SocketUserMessage message;

    public Ping(DiscordClient discord, SocketUserMessage message) {
        this.discord = discord;
        this.message = message;
    }
}

to this
public class Ping(DiscordClient discord, SocketUserMessage message) : ICommand {
    private readonly DiscordClient discord = discord;
    private readonly SocketUserMessage message = message;
}

is this the recommended way to write the constructor in c#? And do I still need the private readonly DiscordClient discord = discord; part or does that get automatically assigned.
Was this page helpful?