farkhatovich2017-08-17 15:44:23
C++ / C#
farkhatovich, 2017-08-17 15:44:23

Advantage of using Expression instead of Func?

When is Expression> used instead of Func<T>, and what advantage does this provide?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Roman, 2017-08-17


Stanislav Makarov, 2017-08-21

These are completely different things.
Func is a standard functor type that allows you to pass/store some behavior or calculation and treat the function as if it were a value.
Expressions are not functors, they are expression trees. You can compile them into code to get a function that can be wrapped in a Func, but you can use an expression in completely different ways, such as displaying its contents in one way or another, or compiling an expression not into code at all, but, for example, into a SQL query, like, EMNIP, makes LINQ-to-SQL. An expression is a data structure, not a functor that can be called.
If it's not clear, I advise you to google for "functor" and "syntax tree", as well as look at examples on MSDN about compiling Expressions. Too much mat here. parts to explain in two sentences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question