Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lambda expression

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
0
0
US
I am trying to understand the Lambda expression.

I found that it does make anonymous delegates a little clearer.

For example I have the following where I am setting up SqlParameters:

Code:
            List<SqlParameter> parms = new List<SqlParameter>();
            parms.Add(database.SetParameter("@Friend",SqlDbType.Int,2));
            parms.Add(database.SetParameter("@Client",SqlDbType.VarChar,50,"Joes bar and grill"));

            parms.Find(delegate(SqlParameter sp) { return sp.ParameterName == "@Client"; }).Value = "Test 1";

            parms.Find(c => c.ParameterName == "@Client").Value = "Test 2";

In the first .Find expression I am using an anonymous delegate which is a little more complicated. But the 2nd .Find uses a Lambda. Both work but the Lambda is simpler.

What I don't understand is what the "c" is? I assume it is just saying that c is an SqlParameter (without the delegate expression).

I assume this is like saying:

Using "c" as an SqlParameter, find an instance of an SqlParameter in our list where c.Parameter name is equal to "@Client".

Is it faster than the delegate?

Thanks,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top