<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Matt Manela's Blog : Visual Basic</title><link>http://blogs.msdn.com/matt/archive/tags/Visual+Basic/default.aspx</link><description>Tags: Visual Basic</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Visual Basic .NET Late Binding Explored</title><link>http://blogs.msdn.com/matt/archive/2007/12/15/visual-basic-net-late-binding-explored.aspx</link><pubDate>Sat, 15 Dec 2007 12:14:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6775904</guid><dc:creator>MattManela</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/matt/comments/6775904.aspx</comments><wfw:commentRss>http://blogs.msdn.com/matt/commentrss.aspx?PostID=6775904</wfw:commentRss><description>&lt;p&gt;In a &lt;a href="http://blogs.msdn.com/matt/archive/2007/12/06/lambda-expressions-are-more-fun-in-visual-basic-net.aspx" target="_blank"&gt;previous post&lt;/a&gt; I mentioned how Visual Basic .NET's&amp;nbsp; lambda expressions are more fun and easy to use than C#'s.&amp;nbsp; My inspiration for this statement was the fact that in VB .NET you are able to implicitly define a lambda expression in this way:&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; f = &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;(x) x + x
Console.WriteLine(f(5)) &lt;span style="color: #008000"&gt;'Outputs: 10&lt;/span&gt;
Console.WriteLine(f(&lt;span style="color: #006080"&gt;"matt"&lt;/span&gt;)) &lt;span style="color: #008000"&gt;'Outputs: mattmatt&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When I began looking at this I realized that the type of &lt;strong&gt;x&lt;/strong&gt; was automatically set as Object.&amp;nbsp; That makes sense since its the most basic type but then I wondered how VB is resolving operations like x + x, x * x, and x.length when x is an Object.&amp;nbsp; VB can't know at compile time if those functions exists on the type stored in Object.&lt;/p&gt;
&lt;p&gt;Visual Basic deals with these function calls on objects in two different ways.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Mathematical Method call on Object&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If the compiler sees that you are doing a recognized mathematical operation it will call the appropriate method from &lt;a title="Operators Class" href="http://msdn2.microsoft.com/8zx6ct68.aspx"&gt;Microsoft.VisualBasic.CompilerServices.Operators&lt;/a&gt;.&amp;nbsp; This class defines methods such as &lt;b&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.VisualBasic:8.0.0.0:b03f5f7f11d50a3a/Microsoft.VisualBasic.CompilerServices.Operators/AddObject(Object,Object):Object"&gt;AddObject&lt;/a&gt;&lt;/b&gt; which determines the type of the two object and checks if there is an addition operation defined for them, if so it will execute it.&amp;nbsp; If the types are not compatible or don't have addition defined on them an exception will be thrown.&amp;nbsp; Up to this point all of this work is done by using type checking and type casting.&amp;nbsp; If all of these tests then the objects will be reflected on in an internal function called InvokeUserDefinedOperator.&amp;nbsp; This function will figure out if this the type stored in the object type has the addition operator defined and if all is compatible execute it.&amp;nbsp; The heavy use of reflection is held off until it has to be used since it is much slower.&amp;nbsp; Doing the initial type checking and casting using a large table of known types is a big performance boost for this method since mathematical operates are usually used on standard .NET types.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Any other method call on Objects&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In this case the optimization technique used above is not applicable so reflection must be used from the start.&amp;nbsp; To perform this reflection on the objects the &lt;a title="NewLateBinding Class" href="http://msdn2.microsoft.com/1z3a798e.aspx"&gt;Microsoft.VisualBasic.CompilerServices.NewLateBinding&lt;/a&gt; class is used.&amp;nbsp; This class defines methods which wrap many of the basic refection methods &lt;em&gt;(it is not meant to be called directly from your code but I am not sure why that is).&lt;/em&gt;&amp;nbsp;&amp;nbsp; The method &lt;strong&gt;LateGet &lt;/strong&gt;is called on the objects with the given function and it is attempted to be called.&amp;nbsp; If it doesn't exist an exception is thrown, naturally.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is just a brief look into how Visual Basic is using late binding to make lambda expressions easier to use.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6775904" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/matt/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/matt/archive/tags/Visual+Basic/default.aspx">Visual Basic</category></item><item><title>Lambda Expressions are more fun in Visual Basic .NET</title><link>http://blogs.msdn.com/matt/archive/2007/12/06/lambda-expressions-are-more-fun-in-visual-basic-net.aspx</link><pubDate>Fri, 07 Dec 2007 09:33:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6689633</guid><dc:creator>MattManela</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/matt/comments/6689633.aspx</comments><wfw:commentRss>http://blogs.msdn.com/matt/commentrss.aspx?PostID=6689633</wfw:commentRss><description>&lt;p&gt;I love C# and I would never want to do anything to make it seem any less amazing but I have to give credit where credit is due ... to Visual Basic .NET.&amp;nbsp; Yes, I said it.&amp;nbsp; Both languages have been adding features inspired by the functional and dynamic programing world.&amp;nbsp; However, VB .NET has went a few steps further to truly merge imperative, object oriented, dynamic and functional programing into one convenient package.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Much of this functionality comes from the fact that VB .NET has late binding built in to many of its operations.&amp;nbsp; This allows the programmer to be more expressive and "get away" with more.&amp;nbsp; I was aware that VB .NET had some unique features but as a C# programmer I never got around to playing around with it to see how they feel.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;This changed recently when I was fooling around with lambda expressions in C#.&amp;nbsp; I have been casually playing and experimenting with &lt;a href="http://en.wikipedia.org/wiki/Haskell_(programming_language)" target="_blank"&gt;Haskell&lt;/a&gt; (a pure functional programing language) for about a year now and I have become very accustomed with just writing a lambda expression and not worrying about defining its type.&lt;/p&gt; &lt;p&gt;With C# 3.0 I assumed I would be able to do the same thing.&amp;nbsp; I wanted to be able to write C# code that is similar to the following Haskell code:&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;f = \x -&amp;gt; x + x&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I figured this would be done easily in C# with the lambda expressions and implicitly typed variables. So I wrote:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; f = x =&amp;gt; x + x;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I was very pleased with this code, it looked very close to the Haskell.&amp;nbsp; It is concise, clean and quick however it doesn't compile.&amp;nbsp; You get this error:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;Cannot assign lambda expression to an implicitly-typed local variable&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The problem is that C# is strongly typed and is unable to determine what type f should be since it cannot determine what type x is.&amp;nbsp; So, you would have to write something like this:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;,&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; f = x =&amp;gt; x + x;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now, that isn't hard to do but I don't want to have to write out that type every time I want to create a lambda expression.&lt;/p&gt;
&lt;p&gt;I tried the same lambda expression in Visual Basic .NET and ...:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; f = &lt;span style="color: #0000ff"&gt;Function&lt;/span&gt;(x) x + x&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Tada!, that worked like a charm.&amp;nbsp; And when I call f(2) it returns 4, and when I call f("matt") it would return "mattmatt".&lt;/p&gt;
&lt;p&gt;This was the behavior I was looking for.&amp;nbsp; This peaked my interest in VB .NET and since then I have been exploring features in it and seeing how it performs late binding to make this all happen.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After I experiment some more I will write in detail about what is really going on behind the scenes in the VB .NET Compiler.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6689633" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/matt/archive/tags/Haskell/default.aspx">Haskell</category><category domain="http://blogs.msdn.com/matt/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/matt/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/matt/archive/tags/Visual+Basic/default.aspx">Visual Basic</category></item><item><title>Lambda Expressions</title><link>http://blogs.msdn.com/matt/archive/2007/12/04/lambda-expressions.aspx</link><pubDate>Wed, 05 Dec 2007 08:55:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6662588</guid><dc:creator>MattManela</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/matt/comments/6662588.aspx</comments><wfw:commentRss>http://blogs.msdn.com/matt/commentrss.aspx?PostID=6662588</wfw:commentRss><description>&lt;p&gt;With the release of C# 3.0 and Visual Basic 9, both languages added support for lambda expressions. Lambda expressions form the basis of &lt;a href="http://en.wikipedia.org/wiki/Lambda_calculus" target="_blank"&gt;lambda calculus&lt;/a&gt; which (this will seem a bit mathy) is a formal system which is used to explore mathematical and programmatic topics such as recursion and computability.&amp;nbsp; Lambda calculus plays a crucial role in language theory and formed the foundation for functional programing concepts and type systems.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt; &lt;p&gt;In MUCH simpler terms a lambda expression is a concise and easy to write anonymous function.&amp;nbsp; Infact C# and VB they are merely syntactic sugar for anonymous delegates.&amp;nbsp; The inspiration for adding them was to simply make passing functions around less cumbersome.&amp;nbsp; For example:&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt; &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] m = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { 0, 5, 10 };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; Console.WriteLine&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; (&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     m.Where&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     (&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x) &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         { &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; x &amp;gt; 4; &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;         }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;      ).Average()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;  );&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt; //Outputs: 7.5&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This snippet takes an array of integers, filters it to only values greater than 4, and then takes its average.&amp;nbsp; We pass in an anonymous delegate to the Where clause to define how we want to filter the array.&amp;nbsp; While this works great and is readable it is needlessly verbose.&amp;nbsp; With the addition of lambda expression that code becomes:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] m = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[]{0, 5, 10};&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; Console.WriteLine&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; (&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     m.Where(x =&amp;gt; x &amp;gt; 4).Average()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; );&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; //Outputs: 7.5&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now I can hear everyone screaming "SO WHAT!".&amp;nbsp; And I will admit it isn't a huge change, but it is cleaner and easier to read.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6662588" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/matt/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/matt/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/matt/archive/tags/Visual+Basic/default.aspx">Visual Basic</category></item></channel></rss>