Hi I am trying to make a program which ; takes an input txt file then shows its lines in reverse order
I was using File.ReadAllLines so I get a array of strings then I used indexes of the strings and used for loop to reverse the order.
But I did some research and found the File.ReadAllLines is not good for very long txt files so they say I should use File.ReadLines.
But I couldn't understand how to access the lines indexes as I did in string array
My working code is below ( which is written by using File.ReadAllLines) I want to do this with File.ReadLines How can I do this how can I access indexes if I use ReadlLines
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Txt Files Only |*.txt";
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Load Log File";
openFileDialog1.ShowDialog();
textBox1.Text = openFileDialog1.FileName;
checkBox1.Checked = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
checkBox1.Visible = false;
button1.Visible = false;
textBox1.Multiline = true;
textBox1.Height = 200;
textBox1.Width = 600;
button2.Visible = false;
textBox1.ScrollBars = ScrollBars.Vertical;
string[] lines = File.ReadAllLines(openFileDialog1.FileName);
int n = lines.Length;
for (int i = 0; n > i; n--)
{
textBox1.Text += lines[n - 1] + Environment.NewLine;
}
}