title: ||(Or) Logical Operator in Java vs .Net
body: <p>I have been coding in Java(Mainly) and .Net for a while.</p>
  
  <p>What I found is that the <code>||</code> logical operator in .Net is different in result to the <code>||</code> operator in Java.</p>
  
  <p>Lets look at the following Java code:</p>
  
  <pre><code>Object obj = null;
  
  if(obj == null || obj.toString().isEmpty()){
      System.out.println("Object is null");
  }
  </code></pre>
  
  <p>The result of the code above will be:</p>
  
  <p><strong>Object is null</strong></p>
  
  <p>The reason for that is because <code>obj == null</code> is <code>true</code> and the second expression wasn't evaluated. If it was, I would have received a <code>java.lang.NullPointerException</code>.</p>
  
  <p>And if I used the single or (<code>|</code>) I would also received a <code>NullPointerException</code> (Both are evaluated).</p>
  
  <p>My question is the following:</p>
  
  <p><em><strong>If the code was C#, I will always get a ObjectReferenceNotSet etc. exception because the obj value is null and the second expression is always evaluated (Regardless of the operator), meaning the result is different in C# than in Java.
  If I would to change the C# code to work properly, I have to create two if statements.</em></strong></p>
  
  <p><em><strong>Is there not an easier way to do this in C# to be similar to Java? (Keep it in one if with 2 expressions)</em></strong></p>
  
  <p>Thank you.</p>