And add these lines to a ListBox. (Windows Form)
I would use:
String file_name = @"x:\....";
int first_line = 24536;
int last_line = 25536;
for ( int i = first_line; i <= last_line; i++)
{
this.listBox.Items.Add(File.ReadLines(this.file_name).ElementAt(i));
}
But this takes a lot of time to load 1000 lines.
How can I do this more efficiently (faster)?
Currently you’re calling
ElementAteach time – which means reading the file from scratch for each new line.Try this:
(Note that I’ve removed the unconventional underscores from your variable names.)