Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking .HasValue (== true) on a Nullable type still shows InvalidOperationException prompt when calling .Value #53

Open
DonaldRecord opened this issue Apr 24, 2017 · 1 comment

Comments

@DonaldRecord
Copy link

DonaldRecord commented Apr 24, 2017

For this code here, I see a prompt telling me that it is possible to throw an InvalidOperationException (even though it won't) - which is good behavior.

int? bar = null;
var foo = bar.Value; //<-- PROMPT HERE

However, when I check .HasValue, which is pretty much a solid guarantee that calling .Value will not throw an InvalidOperationException, I still get the same prompt.

int? bar = null;
int foo;

if (bar.HasValue)
    foo = bar.Value; //<-- PROMPT HERE
else
    foo = 0;
@dittodhole
Copy link

fyi, using .GetValueOrDefault is a viable workaround here - NIH syndrom alert ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants