Ok, I'm lost. Why is the 1st function WRONG (squiglies in the lambda expression), but the 2nd one is RIGHT (meaning it compiles)?
public static Expression<Func<IProduct, string, bool>> IsValidExpression(string val)
{
return (h => h.product_name == val);
}
public static Expression<Func<IProduct, bool>> IsValidExpression2()
{
return (m => m.product_name == "ACE");
}
Your first function is going to need two arguments. Func<x,y,z>
defines two parameters and the return value. Since you have both an IProduct
and a string
as parameters, you'll need two arguments in your lambda.
public static Expression<Func<IProduct, string, bool>> IsValidExpression(string val)
{
return ((h, i) => h.product_name == val);
}
Your second function is only Func<x,y>
, so that means that the function signature has but one parameter, and thus your lambda statement compiles.
What is the middle string
intended to do? You can make it compile by:
public static Expression<Func<IProduct, string, bool>> IsValidExpression(string val)
{
return (h,something) => h.product_name == val;
}
Or maybe you mean:
public static Expression<Func<IProduct, string, bool>> IsValidExpression()
{
return (h,val) => h.product_name == val;
}
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With