✅ how do you properly handle a "Possible null reference return"?
i've got a property on my class that looks like so
vs is giving me a green squiggly in the
get {}
block saying the value might be null. The program itself compiles and runs but just out of curiosity how do you properly resolve the warning?10 Replies
_CurrentPage
(which really should be spelled _currentPage
fwiw) is declared as nullable, but CurrentPage
isn'tis underscore + lowercase starting letter the generally accepted convention for private backing fields?
underscore is personal preference, but yes, they should be camelCase, not PascalCase
got it. both have to be nullable and prefer camelCase
thanks
also, consider using something like the mvvm toolkit to handle much of the drudgery for you https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/
Introduction to the MVVM Toolkit - Community Toolkits for .NET
An overview of how to get started with the MVVM Toolkit and to the APIs it contains
MVVM source generators - Community Toolkits for .NET
An overview of Roslyn source generators to power MVVM scenarios
do they? i would think neither should be nullable?
now that I think about it yeah probably. idk this is my first time with avalonia and i've only been doing C# for, like, a month now
I would use the MVVM toolkit, it will save you a lot of boilerplate.
so they say, but I've only just gotten the hang of MVVM with reactive
i'll keep it in mind though, thanks
doesn't help that a lot of the reading material on either framework does nothing to introduce you to the pattern