I think i remember seeing something similar to the ?: ternary operator in C# that only had two parts to it and would return the variable value if it wasn't null and a default value if it was. Something like this:
tb_MyTextBox.Text = o.Member ??SOME OPERATOR HERE?? "default";
Basically the equivalent of this:
tb_MyTextBox.Text = o.Member != null ? o.Member : "default";
Does such a thing exist or did I just imagine seeing this somewhere?
The COALESCE expression allows for user-specified NULL-handling. It is often used to fill in missing values in dirty data. It has a function-like syntax, but can take unlimited arguments, for example: COALESCE(a, b, c, x, y, z) .
Uses of Null Coalescing Operator: It is used to replace the ternary operator in conjunction with the PHP isset() function. It can be used to write shorter expressions. It reduces the complexity of the program. It does not throw any error even if the first operand does not exist.
Coalesce is simpler than a CASE statement. It is very much like ISNULL which typically I see used more in code. However, coalesce does have some advantages, including: no truncation, it takes more than 2 parameters, and it is ANSI compliant!
The ?? operator is also known as the null-coalescing operator. It returns the left side operand if the operand is not null else it returns the right side operand.
Yup:
tb_myTextBox.Text = o.Member ?? "default";
http://msdn.microsoft.com/en-us/library/ms173224(VS.80).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With