Чтобы узнать количество строк в файле, Вы можете воспользоваться методом System.IO.File.ReadAllLines()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
using System; namespace lines { class Program { static void Main(string[] args) { string path = "D:\\Python\\algorithms\\tst\\test.txt"; // Указываем путь до файла, в котором мы хотим посчитать строки int count = System.IO.File.ReadAllLines(path).Length; // С помощью метода ReadAllLines().Length подсчитываем общее количество строк Console.WriteLine($"In this file {count} lines"); // Пример вывода : In this file 8 lines } } } |