LINQ Examples Posted

| by Marcie Jones Follow 0 Followers on Aug 31, 2006. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

Scott Guthrie has posted the materials from his recent Language INtegrated Query (LINQ) talk at Tech Ed Australia.  For those looking for detailed code samples to understand LINQ further, download these materials. PowerPoint slides are also included in the download for those who want an overview, and even the slides contain quite a bit of code.

LINQ is a set of extensions for .NET to provide a powerful, native query syntax for C# and VB, allowing developers to perform SQL-like queries against any .NET collection or drop down to raw SQL when needed.  LINQ can also query XML and any LINQ result sequence can be databound to ASP.NET controls.  LINQ for entities (formerly described as "ObjectSpaces") is available with the August ADO.NET CTP.  LINQ is currently planned for release with C# 3.0 / VB9 / Visual Studio Orcas / the .NET framework version tentatively known as 3.5.

Example of a LINQ query:

string [] cities = { “Auckland”, “Oslo”, “Sydney”,
       “Seattle”, “Paris”, “Los Angeles” };

IEnumerable places = from city in cities
       where city.Length > 5
             orderby city descending
       select city;

Further reading on LINQ:

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Beware HTML syntax by Matthias Ernst

There's probably a <string> missing between 'IEnumberable' and 'places'.

Amazing! by Tomasz Blachowicz

I think the LINQ is amazing. Basically it's one of the most amazing features I've ever seen. I'm a big fan of Hibenrate's HQL query, but LINQ looks like HQL on steroids plus XQuery! I wonder how this stuff is implemented.

Take a look at this video:

Re: Beware HTML syntax by Jonathan Allen

That is correct. Alternately, you can use "var" instead of giving it an explicit type. This new syntax looks like dynamic typing, but in fact is statically checked at runtime.

I have a site dedicated to LINQ by Joe Rattz

Please feel free to come visit.

LINQ in Action samples source code by Fabrice Marguerie

If you want to see more LINQ examples, you can download for free the complete source code for all the samples from the LINQ in Action book. The samples for all the 14 chapters are provided in both C# and VB.NET.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

5 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you