Search code examples
c#expression-trees

I don't understand this expression tree


public static Expression<Func<int, int, int>> CreateExpressionTreeLambdaExpression()
{
    return (x, y) => x * y;
}

So I understand that if I wanted to test this method I could do like so, which evaluates to true.

[TestMethod]
public void TestLambdaExpressions_ExpressionTreeLambdaExpression()
{
    var expression = MultiplyDelegate.CreateExpressionTreeLambdaExpression();
    var function = expression.Compile();
    Assert.AreEqual(6, function(2, 3));
}

What I don't seem to grasp is the three int's inside the Expression. Where is the third int being used? Is this some sort of reference to itself?


Solution

  • The two parameters are ints and the result is an int. That makes three ints.