I'm coding on an online IDE that doesn't expose either the program input nor the stdout output, in this particular case (input too big).
Considering file to be an arbitrary string:
if (!string.IsNullOrEmpty(file))
{
string[] splitted = file.Split('.');
if (splitted.Length > 0)
{
string Test = splitted[1];
}
}
How is it possible that the code above returns this error:
UNHANDLED EXCEPTION: System.IndexOutOfRangeException: ~message masked~
at Solution.Solution.Main (System.String[] args) [0x000e4] in solution.cs:6
Line number is always wherever I try to access splitted[1]. This doesn't make any sense: if splitted.Length > 0 then splitted[1] exists.
Is this a bug of the online IDE? Or is there any condition in which a C# string[] can be of Lenght>0 and throw IndexOutOfRangeException while reading it's value at [1]?
Lengthis 1, thensplittedwill have a single element, accessible with the expressionsplitted[0]. Thereforesplitted[1]may use an index that is out of range.