c# - Why would you use Expression<Func<T>> rather than Func<T>? -


I understand lengthy and funk and action representatives. But the expression stumps me in what circumstances do you call a plain old funk & lt; T & gt;

When you want to behave as a lambda expression tree and want to look inside them instead of executing them. For example, obtains SQL expression from LINQ and converts it to the equivalent SQL statement and renders it on the server (rather than performing lambda).

Conceptual, Expression & lt; Funk & lt; T & gt; & Gt; Completely separated to Func & lt; T & gt; . Func & lt; T & gt; indicates a representative which is very much an indicator for a method and expression & lt; Func & lt; T & gt; & Gt; A tree data structure for lambda expression This tree structure describes what Lambda expression does instead of doing the actual thing instead It basically holds data on the structure of expressions, variables, method calls, ... (for example this lambda holds information, some stable + some parameters). You can change this description to the actual method (with Expression.Compile ) or other stuff like this (eg SQL example from LINQ). The task of treating lambda as anonymously and expression trees is purely a compilation time.

  Func & lt; Int & gt; MyFunc = () = & gt; 10; // Similarly: int myAnonMethod () {return 10; }  

An IL method will be compiled effectively, which is nothing and return is 10.

  Expression & lt; Funk & lt; Int & gt; & Gt; My Exercise = () = & gt; 10;  

A data structure will be converted which describes the expression that does not get any parameter and gives value 10:

By compiling time, the compiler generates completely different .


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -