KelTi
"Non-nullable field..." warning even though the value is ensured to be declared
Hi, I am very much a C# beginner so please excuse me if it's a dumb question. I'm learning from the Pro C# book and I have this code:
The question is - why am I seeing this warning? Inside the property "Name" I'm handling both cases - when the value is null and is not null. In both cases, I'm assigning some string value to the variable _empName, ensuring it doesn't end up as null.
If I changed the _empName declaration to "private string _empName = String.Empty" then the warning goes away. I just don't see the need for that since I've already handled the null-case. Is that the desired behavior of the compiler? Why? Thanks for all the help in advance.
12 replies