How do you compare nullable int to int

In my Linq query, I have the following:

.Where(x => x.dtt_ref_no == dtt_ref)

where x.dtt_ref_no - with a value of int int
and dtt_ref is of type int .
What is the correct way to compare these two values?

+4
source share
2 answers

Your code works as if you used ==in int?and int, it will return falseif the nullable value contains no value. So this is the same as if you were writing:

.Where(x => x.dtt_ref_no.HasValue &&  x.dtt_ref_no.Value == dtt_ref)

, Nullable<T>.Equals, int int? .

+5

Equals:

.Where(x => x.dtt_ref_no.Equals(dtt_ref))
0

Source: https://habr.com/ru/post/1612248/


All Articles