Need help with this basic Contains<>() extension method and Lambda expressions

Posted by Polaris878 on Stack Overflow See other posts from Stack Overflow or by Polaris878
Published on 2010-04-02T20:01:42Z Indexed on 2010/04/02 20:13 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

Hi,

Say I have the following class:

class Foo
{
    // ctor etc here

    public string Bar
    {
        get;
    }
}

Now, I have a LinkedList of Foos declared like so: LinkedList<Foo>

How would I write a basic Contains<>() for this?

I want to be able to do this:

Foo foo = new Foo(someString);
LinkedList<Foo> list = new LinkedList<foo>();

// Populate list with Foos

bool contains = list.Contains<Foo>(foo, (x => foo.Bar == x.Bar));

Am I trying to do this correctly?

Thanks

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about c#