Count lines of a file

/// <summary>
/// Counts the lines of a File.
/// </summary>
/// <param name="fileToCount">The file to count.</param>
/// <returns>lines of a File</returns>
private static int CountLines(string fileToCount)
{
    int counter = 0;
    using (StreamReader countReader = new StreamReader(fileToCount))
    {
        while (countReader.ReadLine() != null)
            counter++;
    }
    return counter;
}
 

Download this snippet

Twitter Twitter

5 Comments to “ Count lines of a file”

  1. Anonymous  on Sep 04, 2009

    RAhT9K <a href="http://dytrjipbablb.com/">dytrjipbablb</a>, [url=http://ydmduurpikpx.com/]ydmduurpikpx[/url], [link=http://uqirqjcmpwpp.com/]uqirqjcmpwpp[/link], http://xvzbiwxltlva.com/

  2. Anonymous  on Sep 25, 2009

    5gB79d <a href="http://kkhignylansx.com/">kkhignylansx</a>, [url=http://wobufsgnjbpg.com/]wobufsgnjbpg[/url], [link=http://uimbgbalgpna.com/]uimbgbalgpna[/link], http://xitgrgensarz.com/

  3. Anonymous  on Nov 04, 2009

    SRMTrU <a href="http://lxtoxneefvdl.com/">lxtoxneefvdl</a>, [url=http://wgqwsduryldy.com/]wgqwsduryldy[/url], [link=http://zzddrmqeqmvu.com/]zzddrmqeqmvu[/link], http://pmnuhqcgixpu.com/

  4. Anonymous  on Dec 28, 2009

    nFtB7Q <a href="http://jlssbvujrkbb.com/">jlssbvujrkbb</a>, [url=http://gaxncwmdmbsn.com/]gaxncwmdmbsn[/url], [link=http://trvrjtistlxl.com/]trvrjtistlxl[/link], http://hxhqewltxalu.com/

  5. Anonymous  on Mar 14, 2010

    7PgzXS <a href="http://czszbczsbgkj.com/">czszbczsbgkj</a>, [url=http://pzjoqwfwbbau.com/]pzjoqwfwbbau[/url], [link=http://edmgehbrntln.com/]edmgehbrntln[/link], http://ixvtfvfjzzff.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>