For any .NET developers new to Silverlight, they may find it strange that they are not able to resolve the Find() method when working with Generic collections. This is a very useful method when searching a collection for a particular item.
The Find(*) methods on List were added in version 2.0 of the .NET framework before LINQ. LINQ (which stands for Language INtegrated Query) now provides the First() method, which can be used in a similar way to the List.Find() method.
Since LINQ is available in Silverlight, Microsoft decided not to add the Find methods to List to avoid adding duplicate functionality and to keep the size of Silverlight as small as possible.
LINQ can be used as a replacement for List.Find(Predicate):
using System.Linq;
var list = new List { 1, 2, 3, 4, 5 };
int item = list.First(i => i == 2); // same as calling list.Find(i => i == 2);
No comments:
Post a Comment