Im getting the warning "Non-nullable event 'SomeEvent' must contain a non-null value when exiting constructor. Consider declaring the event as nullable."
Here's a very simplified version of my code which replicates the exact same problem. What am I missing here? Does this have anything to do with .Net 6?
namespace ConsoleApp3
{
public delegate void SomeDelegate(object sender, EventArgs args);
public class NewClass
{
public NewClass(string name)
{
this.name = name;
}
public string name { get; set; }
public event SomeDelegate SomeEvent;
}
}
I know I'm late to the party, but Google sent me here, and the only responses were unsatisfactory. I came upon another answer on StackOverflow that felt a lot better, and you can get a good explanation there.
tl;dr just make the event nullable, because that's what it actually is:
public event SomeDelegate? SomeEvent;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With