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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

android - IBM Worklight 6.1 [Application Error] There was a network error (file:///android_asset/www/index.html) -