I'm trying to make an archiver, where files up to 1 Gb or more are preety common and File class is not really useful. Is there any way to use memory more efficiently to handle bigger files successfully? Here is my most efficient code for this purpouse.
int CountLines(string path)
{
try
{
int counter = 0;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(resPath);
while ((line = file.ReadLine()) != null) counter++;
file.Close();
return counter;
}
catch { return -1; }
}