Q:

How to count the text file which split with newline character

I have a file text which splited by newline character. the text file such this:
merah.dc
kuning.dc
hijau.dc
biru.dc
orange.dc
mahopermanent.dc

I want to count them by splitting with a newline character. so, the count of them are 6. I could only do this with looping:
int count = 0;
string path = "directory\\admin.txt";
StreamReader moco = File.OpenText(path);
string s; 
while ((s = moco.ReadLine())!= null)
{
    count++;
}

I want to count them with a simple way like the PHP syntax:
<?php
$file = file("directory\\admin.txt");
$count = count($file);
echo $count;
?>

The above syntax able to counts them without looping. Just use file() and count(). is any function in C# which equals with that function ?

A:

You can use ReadLines without loading whole file into the memory (of course this method can be useful if your file is large)
int count = File.ReadLines(filename).Count();

