Thread: FindAll Error

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    3

    FindAll Error

    Hi,

    I'm using FindAll to filter a list of files contained in an array. I get the following error:-
    'no overload method FindAll takes 1 arguments', I Presume that I'm missing the argument T[] array from the following definition that pops up in my editor:-

    Code:
    public List<T> FindAll(T[] array,Predicate<T> match)
    However this is not the same as the definition as described
    List.FindAll Method (System.Collections.Generic)

    Any ideas on how this may be resolved?
    Thanks

    My code:-
    Code:
     files = files.FindAll(delegate(FileInfo f) { return f.Extension.ToLower() == ".c" || f.Extension.ToLower() == ".h"; });

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I would, personally, just use a lambda for the predicate:
    Code:
                List<string> files = new List<string>(new string[] { "blah.c", "info.txt", "foo.c", "slapmesilly.der", "bar.h" });
    
                List<string> specificFiles = files.FindAll(f => f.EndsWith(".c") || f.EndsWith(".h"));
    
                foreach (string file in specificFiles)
                    Console.WriteLine(file);
    Result:
    Code:
    blah.c
    foo.c
    bar.h
    Of course, I prefer LINQ, which works on any type that implements IEnumerable<T>. Using the following code you get the same results as above:
    Code:
                string[] files = { "blah.c", "info.txt", "foo.c", "slapmesilly.der", "bar.h" };
    
                foreach (string file in files.Where(f => f.EndsWith(".c") || f.EndsWith(".h")))
                    Console.WriteLine(file);
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  2. Replies: 3
    Last Post: 10-02-2007, 09:12 PM
  3. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM
  4. Replies: 1
    Last Post: 01-11-2007, 05:22 PM
  5. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 01:54 AM