>>>The last code doesn't compile. It says operator ?? can not be applied to short and short.
>>
>>Ah, too bad. I would have expected that to work, but it looks like the operators are weird for shorts. I never would have expected the large difference in behavior between them and ints.
>
>I think its because shorts aren't nullable. You would probably have the same error with an int.
I assumed Max returned a Nullable<T> But it looks like it doesn't (and will actually fail if your query doesn't return any records).
And shorts are nullable (well, not by default but you can do: short? val = null;). That's kind of why I would have expected it to work, since this does:
short? x = null;
short y = 2;
var result = x ?? y;
That means my other post about ?? working with shorts isn't really correct. It does, but one of them has to be nullable which in the case of Max(), wasn't the case.
Anyway, the original query could be rewritten as this, which would avoid an exception when no records are returned:
var lastLocSuffix = _salespointAdapter.GetAll().Max(sp=> (short?)sp.LocSuffix) ?? 0;