I am trying to have a short hand for an if statement as I am building an expression query and if test is null the accessor causes an error.
test != null ? test.Contains("mystring") : NO_VLAUE
I am looking for:
test != null ? test.Contains("mystring")
otherwise ignore.
I know I can use a ?? for is null but is there an inverse.
Thanks in advance.
It sounds like you want
test != null && test.Contains("mystring")Your question as asked doesn’t make sense. All expressions, including the conditional operator, must have a value. What would you expect that expression to evaluate to if
testis null?You probably want it to be false if test is null.
In other words, you want it to be true if test isn’t null and it contains
mystring.