+92 332 4229 857 99ProjectIdeas@Gmail.com

Count Lines In File (C#.net)



The following code shows you how to count lines in file. Reading a text from file line by line and checking until the file ends and adding plus one to counter.





using System.IO;

public void CountLines(string filePath)
{

      TextReader tr = File.OpenText(filePath);

      int countLines = 0;

      while (tr.ReadLine() != null)
      {
          countLines++;
      }
                       

    Console.WriteLine(countLines.ToString());
}

0 comments: