0

idk what to do... xD

string[] textLines = new string[20];

for(int i = 0; i < 20; i++)
{
    textLines = System.IO.File.ReadAllLines(@"C:\Users\Computername\Downloads\Filename.txt");
}
Console.WriteLine("Random Text");
for (int i = 0; i < 20; i++)
{
    Console.WriteLine(textLines[i]);
}

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'

DavidG
  • 104,599
  • 10
  • 205
  • 202
Tolle
  • 1
  • 1
    The number of elements of `textLines[]` will be equal to the number of lines in your file, so if it has less than 20 lines your loop will go off the end. (Also note that you don't need a loop to read `textLines` - just call `ReadAllLines()` once.) – Matthew Watson Aug 28 '19 at 09:43
  • Why don't you just use `ReadAllText()` to read it's all text as a string? – Anduin Aug 28 '19 at 10:04

0 Answers0