0

I have following method:

internal virtual Expression VisitMethodCall(MethodCallExpression m)
    {
        var obj = Visit(m.Object);
        IEnumerable<Expression> args = VisitExpressionList(m.Arguments);
        if (obj != m.Object
            || args != m.Arguments)
        {
            return Expression.Call(obj, m.Method, args);
        }
        return m;
    }

The question is: in which cases args != m.Arguments will return true? Does it compare references or every object condition as well?

1 Answers1

0

It simply compare references. args != m.Arguments will always return true unless they reference to the same object.

If args refer to another object, it will still be true even if the contents of two objects are same.

IEnumerable<Expression> args = m.Arguments.ToList();
bool result = args != m.Arguments; // true

If you want to compare the contents of two enumerables including their order you can use:

Enumerable.SequenceEqual(args, m.Arguments);

More information: https://stackoverflow.com/a/3670089/848765

Community
  • 1
  • 1