Andreas01
Andreas01

Reputation: 75

Invalid expression term '>'

I am using Microsoft Visual Studio 2005 with .NET 2.0. I have a comboBox that I use to select a product. After I select a product I am searching for it in a text file – in the end I want to find the line of that product in the file. However with the following code

int lineNo = lineList.IndexOf(lineList.Find(x => x.StartsWith(select)));

the compiler gives the error :

Invalid expression term '>' 

Is this a problem with the 2.0 framework version of .NET?

Upvotes: 3

Views: 7974

Answers (2)

Felice Pollano
Felice Pollano

Reputation: 33242

Lambda expression are supported starting version 3.0 of the C# language. The framework 2.0 + Vs 2005 pair uses the c# 2.0.

Upvotes: 4

Jon Skeet
Jon Skeet

Reputation: 1499740

I have using Microsoft Visual Studio 2005 with 2.0 Net.

That means you're using C# 2.

But you're trying to use a lambda expression (=>) - a feature introduced in C# 3. It's not the version of the framework that you're using - you could write the same code in VS2008 or later, still targeting .NET 2. It's the version of the language you're using.

You can do something similar in C# 2 with an anonymous method though:

int lineNo = lineList.IndexOf(lineList.Find(delegate(String x)
{ 
   return x.StartsWith(select);
}));

Upvotes: 15

Related Questions