This seems like a really simple thing to do but I cant’t seem to get my ahead around it. I have 10 documents entitled 1.txt to 10.txt. I just want to count the number of lines in each doc and end up with the final summation of the line counts.
This is where I got to.
for (int i = 1; i < 11; i++)
{
int lineCount = File.ReadLines(@i + ".txt").Count();
lineCount += lineCount;
Console.WriteLine("Total IDs: " + lineCount);
}
UPDATE
My docs have carriage returns at the bottom of them which I do not want to include in the count.
You are reinitializing
lineCountevery time. Change it like so:This way you don’t reinitialize
lineCountevery time, and you are simply adding theCountto it for each iteration.