Los Techies : Blogs about software and anything tech!

Expressions Cheat Sheet


I started getting really tired of looking up the translation between the ExpressionType and concrete Expression type (they don’t match up), so I created this cheat sheet that has each ExpressionType, derived Expression type and a simple example.  What’s interesting is a few are only available in VB.NET, but no one really wants non-short-circuited Or/And operators, do they?  You can download the PDF version, or just view the big list in all its glory:

ExpressionType Type Example
Add BinaryExpression
int i = 2, j = 3;
Expression<Func<int>> example = () => i + j;
AddChecked BinaryExpression
int i = Int32.MaxValue, j = 1;
Expression<Func<int>> example = () => checked(i + j);
And BinaryExpression
Dim i As Boolean = True, j As Boolean = False
Dim sample As BLOCKED EXPRESSION => c is int;

This is only for C# 3.0, the .NET 4.0 list should grow quite a bit.

Kick It on DotNetKicks.com
Posted Jun 24 2009, 10:36 PM by bogardj
Filed under:

Comments

Mark Nijhof wrote re: Expressions Cheat Sheet
on 06-25-2009 5:33 AM

Nice listing, just curious; why do you have two VB examples in the download? It is not a problem, just wondering :)

-Mark

bogardj wrote re: Expressions Cheat Sheet
on 06-25-2009 8:43 AM

@Mark

Like I said, some examples are _only_ possible in VB.NET.  That includes the And, Or, and Power expression types.  In C#, you have AndAlso, OrElse (these are short-circuited logic), and there is no "Power (exponential)" operator.  It wasn't fun writing those examples :P

Jason N. Gaylord's Blog wrote The Technology Post for June 25th, 2009
on 06-25-2009 4:51 PM

If you are looking to follow this series, be sure to subscribe to my RSS feed at http://feeds.jasongaylord

The Technology Post for June 25th, 2009 | rapid-DEV.net wrote The Technology Post for June 25th, 2009 | rapid-DEV.net
on 06-25-2009 4:56 PM

Pingback from  The Technology Post for June 25th, 2009 | rapid-DEV.net

ASPInsiders wrote The Technology Post for June 25th, 2009
on 06-25-2009 5:59 PM

If you are looking to follow this series, be sure to subscribe to my RSS feed at feeds.jasongaylord.com/JasonNGaylord

I love .NET! » Blog Archive » The Technology Post for June 25th, 2009 wrote I love .NET! &raquo; Blog Archive &raquo; The Technology Post for June 25th, 2009
on 06-25-2009 7:59 PM

Pingback from  I love .NET!  » Blog Archive   » The Technology Post for June 25th, 2009

The Technology Post for June 25th, 2009 | Nexo IT - Information Technology News wrote The Technology Post for June 25th, 2009 | Nexo IT - Information Technology News
on 06-25-2009 11:24 PM

Pingback from  The Technology Post for June 25th, 2009 | Nexo IT - Information Technology News

Sebastian Ullrich wrote re: Expressions Cheat Sheet
on 06-26-2009 3:13 PM

The inline list got a bit mangled. And I bet you _do_ know the C# non-short-circuiting operators: & and | ;)

bogardj wrote re: Expressions Cheat Sheet
on 06-26-2009 3:23 PM

@Seb

Oh wow, forgot about those.  Thanks!  Something with Community Server jacked up my table...oh well...

lilikindsli wrote re: Expressions Cheat Sheet
on 10-04-2009 7:49 PM

7Bf6zq I want to say - thank you for this!

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems