Trying to understand required members
I can't seem to set the value of a required member through a subclass's constructor.
https://dotnetfiddle.net/Gz6b7M
Any help is appreciated.
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
8 Replies
required is purely for the object initializer
What you're seeing is intended
got it, thanks
how do i handle this "non-nullable property must contain a non-null value when exiting constructor" warning?
I agree it would be nice if the code knew the value is technically not "required" in the child class, but that's unfortunately not how c# works
yea the keyword is a little misleading
this warning appears when i remove the
required
keywordI would give Animal a constructor that takes a string
And inheriting classes can call the
: base()
constructorgot it
thanks
thanks i'll take a look at it
What the
That's new to me
Make a factory function for dog