Jeremy
Jeremy

Reputation: 46400

Linq on windows phone

It appears I can use the .Where, .First, etc linq expressions in a Windows Phone 7 class library, but not Contains or FindIndex. Are they really not available at all, or is there something else I need to include to access them?

Upvotes: 2

Views: 900

Answers (3)

Cœur
Cœur

Reputation: 38697

For FindIndex, you can create the method in a class helper:

public static int FindIndex<TSource>(this List<TSource> list, Func<TSource, bool> match)
{
    return list.IndexOf(list.FirstOrDefault(match));
}

Then it will work normally.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1501996

You should be able to use Contains, but FindIndex isn't part of LINQ - it's a method on List<T> normally. However, it's not part of List<T> in Silverlight.

If you're having trouble with Contains, please show a piece of code which is failing.

Upvotes: 4

Waleed
Waleed

Reputation: 3145

Contains already exists in WP7

System.Linq.Enumerable.Contains

For FindIndex, a work arround like this should be sufficient

var index = YourList.IndexOf(YourList.FirstOrDefault(selector));

Upvotes: 3

Related Questions