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 rea开发者_运维知识库lly not available at all, or is there something else I need to include to access them?
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.
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));
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.
精彩评论