[英]Error 95 'System.Array' does not contain a definition for 'FindIndex'
I am converting my existing Windows Phone 8 app to WP 7.1. 我将现有的Windows Phone 8应用程序转换为WP 7.1。 However I've encountered an error
但是我遇到了一个错误
'System.Array' does not contain a definition for 'FindIndex'
in this line. 在这一行。 What am I missing?
我想念什么?
index = Array.FindIndex(AnswerLevelArr, s => s.Contains(CurrentFileName));
Array.FindIndex Method (T[], Predicate) is not supported in Windows Phone 7.1. Windows Phone 7.1不支持Array.FindIndex方法(T [],谓词) 。
Version Information
版本信息
Windows Phone OS
Windows Phone操作系统
Supported in: 8.0支持于:8.0
Instead, you may use Linq
(make sure that you add using System.Linq;
to the top of your file): 相反,您可以使用
Linq
(确保using System.Linq;
添加到文件顶部):
index = AnswerLevelArr
.Select((i, position) => new { Item = i, IndexOf = position })
.First(s => s.Item.Contains(CurrentFileName)).IndexOf;
or: 要么:
int index=0;
var result = AnswerLevelArr.SkipWhile((s, ind) =>
{
if (!s.Contains(CurrentFileName))
{
index++;
return false;
}
else
{
return true;
}
}).First();
according to msdn 根据msdn
public static int FindIndex<T>(
T[] array,
Predicate<T> match
)
http://msdn.microsoft.com/en-us/library/03y7c6xy.aspx http://msdn.microsoft.com/zh-CN/library/03y7c6xy.aspx
you need to include the type? 您需要包括类型吗?
EDIT: index = Array.FindIndex<T>(AnswerLevelArr, s => s.Contains(CurrentFileName));
编辑:
index = Array.FindIndex<T>(AnswerLevelArr, s => s.Contains(CurrentFileName));
EDIT2: Left above up for history but is wrong after further inspection... EDIT2:保留历史记录,但经过进一步检查后是错误的...
If you wanted a find index similar to your method you could provide an override 如果您想要与您的方法类似的查找索引,则可以提供覆盖
int FindIndex(string s)
{
int size = this.length;
for(int i = 0; i < size; i++)
{
if(this[i] = s)
return i;
}
return -1;
}
From Array.FindIndex<T> Method (T[], Predicate<T>)
从
Array.FindIndex<T> Method (T[], Predicate<T>)
Version Information
Windows Phone OS
Supported in: 8.0
It is looks like this method not supported in Windows Phone 7.1
看来
Windows Phone 7.1
不支持此方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.