When I write this snippet in my asp.net Razor C# I was getting Index was outside the bounds of the array from the following code -
when call code below. index outside bounds of array. doesn't split function return array?
@{ array userdata = file.readalllines(datafile); foreach(string line in userdata){ char [] c = new char[]{'^'}; string[] x = line.split(c) ; {<p>@x[1] </p>} } }
you need check x.lenght > 1
you're getting there line.split(c)
returns array 1 element in , therefore you're getting index out of bounds error when trying access 2nd element.
Comments
Post a Comment