Hello LINQ in .NET 2.0
December 31, 2008When using Visual Studio 2008, it is possible to use most of the new language additions of C# 3.0 in a .NET 2.0 project. This because the C# 3.0 compiler is used for both .NET 2.0, .NET 3.0 as well as for .NET 3.5 projects in Visual Studio. This means that local variable inference, object initializers, extension methods, lambda expressions, etc. … can be used in a .NET 2.0 project.
The one thing that is missing however is LINQ because those extensions are packaged in the new System.Core assembly which comes only with .NET 3.5.
However, last week I accidentally stumbled into LINQBridge which enables you to write LINQ to Objects queries targeting .NET 2.0. The only requirements for this is that you need to have Visual Studio 2008 and a reference to the LINQBridge assembly. Note that the current implementation does not support other LINQ providers besides LINQ to Objects (no LINQ to XML and certainly not LINQ to SQL).
The following code is written for targeting the .NET 2.0 runtime.
public class Actor
{
public String FirstName { get; set; }
public String LastName { get; set; }
public Int32 ShoeSize { get; set; }
}
public class Program
{
static void Main()
{
var actors = new List<Actor>()
{
new Actor() { FirstName = "Chuck",
LastName = "Norris",
ShoeSize = 46 },
new Actor() { FirstName = "Adam",
LastName = "Sandler",
ShoeSize = 41 },
new Actor() { FirstName = "Steven",
LastName = "Seagal",
ShoeSize = 48 }
};
var actorsWithBigFeet = from actor in actors
where actor.ShoeSize > 45
select actor;
foreach(Actor bigfoot in actorsWithBigFeet)
{
Console.WriteLine("{0} {1} has shoe size {2}.",
bigfoot.FirstName,
bigfoot.LastName,
bigfoot.ShoeSize);
}
Console.Read();
}
}
Just to let you know that if you are stuck with .NET 2.0 like me, then life shouldn’t be that bad either ;-). Kudos to project owners for making this possible for us poor developers!
If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or check out the books section. Feel free to reach out at info. @ principal-it .be
Jan Van Ryswyck
Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.
Comments
Writing Maintainable
Unit Tests
Watch The Videos
Latest articles
-
Contract Tests - Parameterised Test Cases
June 28, 2023
-
Contract Tests - Abstract Test Cases
April 12, 2023
-
Contract Tests
February 1, 2023
-
The Testing Quadrant
June 15, 2022
-
Tales Of TDD: The Big Refactoring
February 2, 2022
Tags
- .NET
- ALT.NET
- ASP.NET
- Agile
- Announcement
- Architecture
- Behavior-Driven Development
- C++
- CQRS
- Clojure
- CoffeeScript
- Community
- Concurrent Programming
- Conferences
- Continuous Integration
- Core Skills
- CouchDB
- Database
- Design Patterns
- Domain-Driven Design
- Event Sourcing
- F#
- Fluent Interfaces
- Functional Programming
- Hacking
- Humor
- Java
- JavaScript
- Linux
- Microsoft
- NHibernate
- NoSQL
- Node.js
- Object-Relational Mapping
- Open Source
- Reading
- Ruby
- Software Design
- SourceControl
- Test-Driven Development
- Testing
- Tools
- Visual Studio
- Web
- Windows
Disclaimer
The opinions expressed on this blog are my own personal opinions. These do NOT represent anyone else’s view on the world in any way whatsoever.
About
Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of Writing Maintainable Unit Tests. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Thinking and learning about all kinds of technologies since forever.
Latest articles
Contract Tests - Parameterised Test Cases
Contract Tests - Abstract Test Cases
Contract Tests
The Testing Quadrant
Contact information
(+32) 496 38 00 82
info @ principal-it .be