Is there a quick way to say
Where (data.x == (If notempty x = y else x = default))
Assuming the data being compared is both strings
Compare listitem.string with passed.string - if passed.string isnotempty, else passed.string equals default value.
in a Linq ‘where` query.
Apologies that the question was really badly written.
… As per the comments updated …
Ok, with your clarifications to the original post, I think I see what you’re getting at now.
Try the following clause (where
data.xis your current element andyin the passed argument).I do not believe it’s possible to use the null coalescing operator here, since the variables you are comparing and returning are different.
Old Post:
If what is empty? I’m guessing you’re referring to
y.For a generic type
T, you could use the following clause:where
DefaultValueis a generic function ofTthat returns a so-called “default” value.