I'm getting this warning:
I want to remove this warning.
What happens when it does not find any item with the email address? it will simply return null.
So, you have to tell this method caller that it could also return null and in order to do so, you will simply have to make the return type nullable by appending ? as shown below.
public User? GetUserByEmail(string email)
{
return _users.SingleOrDefault(u => u.Email == email);
}
Similar to this post, you can remove any warning having its code by adding these lines in your csproj:
<PropertyGroup>
<NoWarn>8603</NoWarn>
</PropertyGroup>
Also you may fix it using editorconfig
# CS8603: Possible null reference assignment.
dotnet_diagnostic.CS8603.severity = none