C# 3.0 Features Added for LInQ

by mheydt 15. July 2008 17:45 >
I'm brushing up on my LInQ today for a few reasons.  One is that its been a while since I used it because my current client isn't that far ahead and I need a refresher.  Second is that I want to build up some interview questions.  Third is I need to update an intro to LInQ presentation I have previously built. 

The true reason though is that I want to write out a few of my opinions on the technology, and explain a few things from the perspective of how I see them.  One of those things is how the new C# 3.0 language extensions facilitate LInQ.  I think sometimes that people think that these features were added to C# as independent items that developers have requested.  I don't really see it that way, as I think that although they are useful (and very useful at that) by themselves, that they are only added to the language to allow LInQ.  If they were not added, the expressivness of LInQ statements would be greatly reduced, and as a matter of fact it would not event be possible.

The following are the new C# 3.0 features and how I see them related to LInQ:
  • Local Type Inference
Required for handling query / selection results.  Often (mostly) the type of this object may not be of a type that is defined in the system at compile time.  An example is a projection of just a few properties from a result object (via select) instead of the whole object.  In this case, the compiler / run-time will create an anonymous type whose type (likely a class with with properties) that can be inferred through the a var keyword.  This is tightly intertwined with anonymous types.
  • Anonymous Types
Required to allow the creation of results from where and select queries.
  • Lambda Expressions
Required to efficiently code expressions for the selection and projection steps of a query.  With out them, you would need to declare a delegate (either explicitly or anonymously) which would add to the coding overhead.
  • Extension Methods
Needed to extend existing classes to have new LInQ methods such as .Where, .OrderBy, .Select, ...
  • Object Initializers
Allow the compiler / run-time to efficiently initialize properties of anonymous classes.  Without them a constructor would need to be injected into the anonymous class.
  • Query Expressions
Provide a syntax similar to SQL, which is used to manipulate data, but provides a short-hand for the coder that the compiler converts into specific classes and method in LInQ.

Tags:

.Net | C# | LInQ

blog comments powered by Disqus

about the author

I'm a .NET, XAML, and iOS polyglot that loves playing with new things and making cool and innovative stuff.  I am also a Mac junkie.

I am Principal Technologist for SunGard Global Services in NYC, in their Advanced Technologies practice, and I work extensively with SunGard's energy and financial customers.

Note the the posting on this blog are my own and do not represent the position, strategies or opinions of SGS.

twitter

I can't stop thinking big!
Sunday 1:08AM via WindowsLive
Just watched Moneyball. That's my pick for best movie this year.
Saturday 3:51PM via WindowsLive
@vincebelpiede: Report: Skype For Windows Phone Beta Imminent http://t.co/KYNjgg1L#mhtnd
Wednesday 8:39AM via Twitter for Mac
@mashable: Kinect Fusion Will Turn Gaming (and More) Into a 3D Fun House - http://t.co/Ihrq2fY2#mhtnd
Wednesday 8:39AM via Twitter for Mac
New Kinect SDK: http://t.co/57MvA5L5 #mhtnd
Wednesday 8:39AM via Twitter for Mac
Follow me on Twitter

recent comments

None

month list