my code is :
    int linenumber = File.ReadLines(path).Count();
but it takes long time (about 20 second) for files about 1 gig size .
so does anyone know better way to solve this problem ?
Update 6 :
I have tested your solutions :
for a file about 870 mb size :
method 1 : { my code time(seconds) : 13 }
method 2 : (from MarcinJuraszek & Locke) (the same) {
time(seconds) : 12 }
method 3 : (from Richard Deeming) { time(seconds) : 19 }
method 4 : (from user2942249) { time(seconds) : 13 }
method 5 : (from Locke) { time(seconds) : 13 is the same for lineBuffer = {4096 , 8192 , 16384 , 32768} }
method 6 : (from Locke edition 2) { time(seconds) : 9  for Buffer size = 32KB , time(seconds) : 10  for Buffer size = 64KB  }
As i said , in my comment , there is an application (native code) , that opens this file in my pc in 5 second. therefore this is not about h.d.d speed.
By Compiling MSIL to Native Code , the difference was not obvious.
Conclusion : at this time , the Locke method 2 is faster than other method.
So i marked his post as Answer . but this post will be open if any one find better idea.
I gave +1 vote up for dear friends who help me to solve the problem.
Thanks for your help. interesting better idea . Best Regards Smart Man
 
     
     
     
     
    