Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare two lambda expressions? [duplicate]

Tags:

c#

.net

lambda

Possible Duplicate:
How to check if two Expression<Func<T, bool>> are the same

I need to compare two lambda expressions, to check equality. Basicly, the two following lambda are identical:

Expression<Func<int, bool>> exp1 = (Foo f) => f.Bar().StartsWith("F");
Expression<Func<int, bool>> exp2 = (Foo b) => b.Bar().StartsWith("F");

How can I check if exp1 does the same thing that exp2 does?

like image 427
Jonathas Costa Avatar asked Dec 26 '12 17:12

Jonathas Costa


People also ask

What does => mean in lambda?

In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.

Can a lambda statement have more than one statement?

The body of a statement lambda can consist of any number of statements; however, in practice there are typically no more than two or three.

What are the three parts of a lambda expression?

A lambda in Java essentially consists of three parts: a parenthesized set of parameters, an arrow, and then a body, which can either be a single expression or a block of Java code.


1 Answers

You might need to use IComparer or mock classes

View c-sharp-lambda-expressions-and-icomparer and comparing-simple-lambda-expressions

like image 200
Rahul Ranjan Avatar answered Sep 28 '22 16:09

Rahul Ranjan