alternative of list.FindIndex(x => x.UpperLimit >=lInput && x.LowerLimit <= lInput); in .net 2.0 framework

I realized lamba is not supported by .net 2.0; would like to know the alternative of following statement in .net 2.0

list.FindIndex(x => x.UpperLimit >= dblInput && x.LowerLimit <= dblInput);

Jon Skeet
people
quotationmark

I realized lamba is not supported by .net 2.0

That's not true. You can use lambda expressions to create delegates in .NET 2.0 with no problem. You need a C# 3 compiler (or later), that's all - it's a compile-time transformation which doesn't need framework or CLR support. You won't be able to get expression tree support without a separate library, but that's a different matter, and you don't need that for List<T>.FindIndex.

So long as you're building with a C# 3+ compiler, the code you've given should be fine.

If you're using a C# 2 compiler, you can use an anonymous method instead:

// Change the type of x appropriately. You haven't told us the type of list.
int index = list.FindIndex(delegate(Foo x) { 
    return x.UpperLimit >= dblInput && x.LowerLimit <= dblInput;
});

That's pretty horrible though, and I would strongly encourage you to use a more recent version of the C# compiler if you possibly can. The C# 3 compiler was released in November 2007... do you really need to use something older than that?

people

See more on this question at Stackoverflow