I've got simple class, something like this:
public class myClass
{
public static readonly string[] stringArray= { "one", "two" };
private string myString;
public myClass (int _index)
{
if(_index > (stringArray.Length - 1) || _index < 0)
{
throw new IndexOutOfRangeException("Bad index.");
}
else
{
myString = stringArray[_index];
}
}
}
I'm running simple constructor: myClass example = myClass(5); and I've got error. It shouldn't leave constructor without trying create new object?
I don't understand how throw works there.
Edit: Sorry, I made a mistake. There should be stringArray.Length -1 in if section.