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

Prefer == null and != null over HasValue with Nullable<T> #58

Open
amanda-mitchell opened this issue Mar 5, 2019 · 3 comments
Open

Comments

@amanda-mitchell
Copy link
Contributor

I could easily be persuaded to go the other way on this one, but the point is that we should have exactly one way of doing it.

@ddunkin
Copy link
Member

ddunkin commented Mar 5, 2019

+1 for comparison to null.

@ejball
Copy link
Member

ejball commented Mar 5, 2019

I also prefer comparison with null.

It feels a little strange, since I also prefer Value to a C-style cast.

int? number = TryGetNumber();
if (number != null) // vs. number.HasValue
    SetNumber(number.Value); // vs. (int) number

But I'm really hoping that they will eventually support ! on Nullable<T> values. (If there's an issue for that, I can't find it.)

int? number = TryGetNumber();
if (number != null)
    SetNumber(number!);

@amanda-mitchell
Copy link
Contributor Author

It feels a little strange, since I also prefer Value to a C-style cast.

I started to also create an issue to require Value instead of C-style casts, but the internal inconsistency bothered me enough that I stopped short of doing so.

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

No branches or pull requests

3 participants