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 -

google shop client API returns 400 bad request error while adding an item -