no System.IO.File.ReadLines(file).Count() in .Net 4?

c#

Solution

`Count<T>()` is an extension method for objects of `IEnumerable<T>`. Try adding a `using` statement for the namespace `System.Linq`.

Problem

I am trying to read the number of lines of a file I found here (stackoverflow) that the best way to read the number of lines in a large file is by using the following code: ``` int count = System.IO.File.ReadLines(file).Count(); ``` However, I can't make it compile. Does any know what is the problem? Error 5 `'System.Collections.Generic.IEnumerable<string>'` does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type `'System.Collections.Generic.IEnumerable<string>'` could be found (are you missing a using directive or an assembly reference?) Thanks, Eyal

Original source

Related problems