-1

This is what I have but there isn't anything that talks about how to delete multiple specific lines, for example, from line 2 - 8.

var file = new List<string>(System.IO.File.ReadAllLines(lsbMatches.SelectedItem.ToString()));//location
file.RemoveAt(2);// i want to change this to multiple lines
File.WriteAllLines(lsbMatches.SelectedItem.ToString(), file.ToArray());//location
haldo
  • 11,588
  • 5
  • 34
  • 42
  • You are probably better off using LINQ `Where` and passing an `IEnumerable` through to `WriteAllLines` as this is far more efficient. – Charlieface Mar 15 '21 at 01:02

2 Answers2

0

You can use RemoveRange because you have converted your text file into a list of strings.

https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.removerange?view=net-5.0

0

You're best option is to do :

file.RemoveRange(2, 6);
Abanslash
  • 57
  • 6