'Understanding why I'm still getting CS8618 Error In Constructor
I'm getting to grips with the nullable change, but I've hit something that's giving CS8618 (Nullable field must contain non-null) but I don't think it should be.
Basically I have a private field, and my constructor calls an 'init/setup etc' method, the method does set the private field, but it's not happy.
i.e.
public class Test
{
private object bob;
public Test()
{
Init();
}
private void Init()
{
bob = new object();
}
}
The compiler highlights the constructor as being in error. Can I tell it somehow that Init() does what it wants? or is there something I'm missing that means that Init() might not be called in some situations which would make the warning valid?
I've tried a few ! at the end in places, but that doesn't seem to be it. If I move the code from Init() into the constructor the error does go away in this trivial example and the one in my code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
