DEV Community

Discussion on: An Introduction to C# Expression Trees

Collapse
 
mdfrenchman profile image
Mike French

Interesting, but WHY would we do this with expressions? All of the examples add complexity for no reason. And I’m having a hard time of thinking of a useful application.

How something is done is great but when and why is even more useful.

Collapse
 
mokenyon profile image
Morgan Kenyon

Hi Mike, great question. I agree, at the end of the day if it adds complexity for complexities sake, it's not very useful.

I talk a little bit about the "portability" or expressions. Since expressions are code defined as a data structure, data structures can be passed around.

I also expand a bit on this topic in my second article. In real world, libraries like Entity Framework Core heavily use Expressions.

Linq queries are converted into Expressions, then those expressions are passed to the specific database formatters. Be it SqlServer, Oracle, Postgres, etc.

Expressions are definitely more of a feature targeting library developers versus web applications.

So more than likely you probably won't need to use them, but have used other nuget packages that use them heavily.