C#C
C#2y ago
Immortal

✅ Best practices regarding non-nullable property warnings?

Hi, In my Discord Bot project I get some warnings for example:

Non-nullable property 'Config' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

I understand what it means and why I get it but not sure if it's ok for me to ignore it or if it indicates bad practices so I should learn to write it better.

Here is my Program.cs file:
namespace self_bot
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var bot = new Bot();
            bot.RunAsync().GetAwaiter().GetResult();
        }
    }
}

And I've attached the Bot.cs file contents because it's too long to be put in this message.

The warning also shows with the Client and Slash properties.

From looking online the best way would either be to use lazy initialization or a constructor but I have no clue which is best for my project so would like advice from more experienced people.

Thanks
bot.txt5.05KB
Was this page helpful?
✅ Best practices regarding non-nullable property warnings? - C#