What is wrong with the code?

public static bool ParseDir(string directory) //вызываем этот метод { bool isRDK = false; Directory.GetFiles(directory) .Select(file => new FileInfo(file)) .Any(f => f.Extension == ".rdk") .Select(f => f.FullName) .ToList() .ForEach(x => { Console.WriteLine(x); FileParser.ExportFile(x); isRDK = true; }); return isRDK; } 

Why swears: "bool" does not contain a definition for "Select"

  • four
    You should not use imperative constructs with LINQ queries. I would write this: var filteredFileNames = Directory.EnumerateFiles (directory) .Where (path => Path.GetExtension (path) == ".rdk"); foreach (var path in filteredFileNames) {Console.WriteLine (path); FileParser.ExportFile (path); isRDK = true; } - VladD
  • Granted, the source code is very hard to read. - Ivan Navoznov

1 answer 1

Because string

.Any (f => f.Extension == ".rdk")

Returns bool and you call .Select(...) for it (see next line .Select(...)

Solution: instead of .Any(f => f.Extension == ".rdk") put .Where(f => f.Extension == ".rdk")