Iif equivalent in C#

C# has the ? ternary operator, like other C-style languages. However, this is not perfectly equivalent to IIf(); there are two important differences. To explain the first difference, the false-part argument for this IIf() call causes a DivideByZeroException, even though the boolean argument is True. IIf() is just a function, and like all functions all …

Read more

C# conditional operator error Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

The conditional operator is an expression, not a statement, that means it cannot stand alone, as the result has to be used somehow. In your code, you don’t use the result, but try to produce side effects instead. Depending on the condition before the ? the operator returns the result of either the first or …

Read more

PHP if not statements

Your logic is slightly off. The second || should be &&: You can see why your original line fails by trying out a sample value. Let’s say $action is “delete”. Here’s how the condition reduces down step by step: Oops! The condition just succeeded and printed “error”, but it was supposed to fail. In fact, …

Read more

How to check if my string is equal to null?

As further comment, you should be aware of this term in the equals contract: From Object.equals(Object): For any non-null reference value x, x.equals(null) should return false. The way to compare with null is to use x == null and x != null. Moreover, x.field and x.method() throws NullPointerException if x == null.