Search code examples
c#windows-phone-8windows-store-appsportable-class-library

c# portable class library: find item in list by property


I am developing a Windows Phone 8 application where I use portable class libraries. There seems to be no linq-support for these kind of projects.

Is there a good/recommended way to search for an item in a list based on a property value?

If i get it right, I can't use something like: list.Find(i => i.ID == someValue);

Edit: I'm currently using foreach but would like to know if there is another solution.

The PCL settings are: .NET 4.5, Silverlight 4, Windows Phone 7.5 and Windows Store


Solution

  • Because you don't need Xbox then you can use LINQ in PCL. Blog post explaining restrictions when using PCL.

    LINQ code:

    list.FirstOrDefault(i=>i.ID==someValue);