Friday, September 03, 2010

09/03: Func/Action And Lambda Exprssion

 

Func code:

 

Func<string, bool> Istruefunc = username =>
               {
                   return username == "yuyi";
               };

 

Equivalent Lambda expression:

Expression<Func<string, bool>> IsTrue = username =>
               username == "yuyi";

Will receive error with following :

Expression<Func<string, bool>> test = username =>
                {
                    return username == "yuyi";
                };

 

 

But we can do this :

 

public static bool method(string username)
        {
            return username == "yuyi";
        }

Expression<Func<string, string>> test = username =>        
                 method(username);

0 Comments:

Post a Comment

<< Home