Skip to main content
2 of 2
added 65 characters in body
Stephen
  • 8.8k
  • 3
  • 31
  • 43

I have to use Visual Studio 2005. What are good alternatives to using LINQ?

I have recently started a new job and am being forced to use VS 2005 and .NET 2. This has been quite painful for a number of reasons, but the one big change from VS 2005 to its successors was the introduction of LINQ and extension methods.

A common pattern that I used to follow when using enumerations was the following:

foreach(var myObject in myObjects.Where(x => x.Property == someValue)
{
    //Do some stuff
}

What I am having difficulty with is coming up with a succinct way of expressing the same statement in C# 2. The best I have come up with is the following:

foreach(MyObject myObject in myObjects)
{
    if(myObject.Property == someValue)
    {
        //Do some stuff
    }
}

Is there a more effective or efficient way of writing this code?

How would you write C# 2 code so that it can most easily be transformed into C# 5 code (we will be upgrading to VS2012/.NET 4.5 after the next release)?

Stephen
  • 8.8k
  • 3
  • 31
  • 43