Preventing Index Out of Range Error
<p>I want to write a check for some conditions without having to use try/catch and I want to avoid the possibilities of getting Index Out of Range errors</p>

<pre><code>if (array.Element[0].Object.Length &gt; 0 || array.Element[1].Object.Length &gt; 0) //making sure there's at least one Object array that has values
 {                
    if (array.Element[0].Object[0].Item.Length != 0 || array.Element[1].Object[0].Item.Length != 0) //this is where I check that at least one of the Items (strings) is not empty
       {
           // execute code here
       }
 }
</code></pre>

<p>So the problem I am facing is that in the second check I need to see whether I have one Item that is not empty. However, If I don't have <code>Element[1]</code>, I get the Index Out of Range exception. The problem is that there could be 2 Elements and one(or both) of them may have empty Object arrays. The code will have to be executed only if one of thos Item strings is not empty.</p>

<p>Hopefully, I explained it well. How do I go about avoiding getting that exception under any condition?</p>
