The reason is quite obvious. See updated procedure.
static void lineChanger(string newText, string fileName, int line_to_edit)
{
string[] arrLine = File.ReadAllLines(fileName);
Console.WriteLine($"arrLine.Length: {arrLine.Length}\tline_to_edit: {line_to_edit}");
if(line_to_edit < 0 || line_to_edit > arrLine.Length-1)
{
Console.WriteLine($"Note: line to edit ({line_to_edit}) is bigger than number of lines ({arrLine.Length}) in file or less than 0");
return;
}
arrLine[line_to_edit] = newText;
File.WriteAllLines(fileName, arrLine);
}
BTW:
Do not use
"C:\\Users\\x\\Documents\\Random.txt"
several times. Create and use a variable, for example:
string sFile = "C:\\Users\\x\\Documents\\Random.txt";
lineChanger(textBox5.Text, sFile, counter);