The compiler replaces null
comparisons with a call to HasValue
, so there is no real difference. Just do whichever is more readable/makes more sense to you and your colleagues.
More Related Contents:
- What is a NullReferenceException, and how do I fix it?
- Nullable types and the ternary operator: why is `? 10 : null` forbidden? [duplicate]
- Setting Objects to Null/Nothing after use in .NET
- How to check if an object is nullable?
- What is the difference between “x is null” and “x == null”?
- Nullable type is not a nullable type?
- What does “DateTime?” mean in C#?
- How to parse a string into a nullable int
- What are lifted operators?
- How to set enum to null
- Easier way of writing null or empty?
- Shortest way to check for null and assign another value if not
- Why GetType returns System.Int32 instead of Nullable? [duplicate]
- How to do ToString for a possibly null object?
- Invalid cast from ‘System.Int32’ to ‘System.Nullable`1[[System.Int32, mscorlib]]
- Optional return in C#.Net
- Where in memory are nullable types stored?
- Why does .ToString() on a null string cause a null error, when .ToString() works fine on a nullable int with null value?
- Best way to check if a Data Table has a null value in it
- How is the boxing/unboxing behavior of Nullable possible?
- Are nullable types reference types?
- string.Empty vs null.Which one do you use?
- Boxing / Unboxing Nullable Types – Why this implementation?
- Why does null need an explicit type cast here? [duplicate]
- What does exclamation mark mean before invoking a method in C# 8.0? [duplicate]
- Why doesn’t the conditional operator correctly allow the use of “null” for assignment to nullable types? [duplicate]
- how are nullable types implemented under the hood in .net?
- Getting ServiceStack to retain type information
- Is it possible to create a new operator in c#?
- How to Change Pixel Color of an Image in C#.NET