IEnumerable에 대한 FindAll 메서드를 사용하여 조건부 조건을 기준으로 필터링했습니다. 배열과 목록 모두에 공통입니다. 때문에 SIL은빛 창 전화 7에서 확장 메서드가 작동하지 않습니다.
에서 코드 : 내 응용 프로그램에서 나를 위해 작동하지 않는 이유
public static IEnumerable<T> FindAll<T>(this IEnumerable<T> tCollection, Func<T, bool> predicate)
{
if (null == tCollection) yield return default(T);
using (IEnumerator<T> iterator = tCollection.GetEnumerator())
{
if (!iterator.MoveNext())
{
yield return default(T);
yield break;
}
do
{
if (predicate(iterator.Current))
yield return iterator.Current;
}
while (iterator.MoveNext());
}
}
내가 부르고 때 나를 위해 작동하지 않습니다 ..
List<string> strings = new List<string> { "Kumaran", "Raj", "Kannan", "Karthi", "Gopal" };
IEnumerable<string> str = strings.FindAll(item => item.StartsWith("K"));
내가 알 수 있습니다.
안녕 Dinesh "나에게 도움이 안된다"는 말에 정교하게 대답 해주세요. –
목록이 비어 있거나 참조가 null 인 경우 왜 단일 요소를 생성 하시겠습니까 (기본값)? 목록에 항목이 있고 그 중 하나도 조건부와 일치하지 않는 경우 왜 그렇지 않습니까? 그리고 왜 당신은 내장 된'Enumerable.Where' 메서드를 사용하지 않는 것일까 요? –
Silverlight에서 다른 동작이 나타나는 이유는'List'에 이미'FindAll' 메서드가 있기 때문에 메서드가 데스크톱 .NET에서 전혀 호출되지 않기 때문입니다 (이 경우와 같이 깨지지는 않습니다) . –