0

I'm getting this warning:

enter image description here

I want to remove this warning.

0

3 Answers 3

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

2

remove following tag in .csproj file

<Nullable>enable</Nullable>

Comments

-2

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 

2 Comments

... defeating the purpose of Nullable Reference Types
@HansKesting just giving what SO want.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.