How does C# lambda work?

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-03-08T02:46:52Z Indexed on 2010/03/08 3:30 UTC
Read the original article Hit count: 633

Filed under:
|
|

I'm trying to implement method Find that searches the database.

I want it to be like that:

var user = User.Find(a => a.LastName == "Brown");

Like it's done in List class. But when I go to List's source code (thanks, Reflector), I see this:

public T Find(Predicate<T> match)
{
if (match == null)
{
    ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
for (int i = 0; i < this._size; i++)
{
    if (match(this._items[i]))
    {
        return this._items[i];
    }
}
return default(T);
}

How can I implement this thing? I need to get those parameters to make the search.

© Stack Overflow or respective owner

Related posts about c#

Related posts about lambda