Now only if I could convince people to quit thinking FirstOrDefault will always return null if it can't find anything.
It does what it says it does, default value. It just so happens that for objects that is null
(I say this because I had to prove to someone once that their if statement would always evaluate to true. Lol)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
.NET's
FirstOrDefault()
method when accessing LINQ. I find it super clear :)Less clear along those lines is the
||=
operator.What does ||= do?
Alex
Hey, PHP has the coolest operator: the SPACESHIP operator <=>
The
<=>
is for evaluation and||=
is for assigment, the??
null coalescing operator is more close to it but are not the same.Now only if I could convince people to quit thinking
FirstOrDefault
will always returnnull
if it can't find anything.It does what it says it does, default value. It just so happens that for objects that is
null
(I say this because I had to prove to someone once that their if statement would always evaluate to true. Lol)