Can someone explain the difference between:
if(object?.Count > 0){
//code
}
and:
if(object != null && object.Count > 0){
//code
}
Or are they doing the same thing? Thank you.
Can someone explain the difference between:
if(object?.Count > 0){
//code
}
and:
if(object != null && object.Count > 0){
//code
}
Or are they doing the same thing? Thank you.
The question mark is the null-conditional operator (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators). It is shorter and more precise to write if you are using C# 6 or above.