Johnny Nguyen

Johnny Nguyen

  • NA
  • 6
  • 8.1k

the Array

Apr 18 2011 11:25 PM
When I run the code bellow in the console application I got the error " Index was outside the bounds of the array". Why do I get the error and how to fix it?

static void Main(string[]args)
{
        string aString= "This is a string";
        string [] sArray= aString.Split(' ');
        Console.WriteLine(sArray[sArray.Length]);
}

I thinks,should I convert the sArray.Length to int because it still be a string form. right? 

Answers (2)