简体   繁体   中英

List.Exists missing within Portable Class Library

I am creating a Portable Class Library (PCL) and I am trying to use List.Exists() and List.TrueForAll(), but I am being told that System.Collections.Generic.List does not contain a definition for either Exists or TrueForAll. The PCL I am creating is to work across the .Net 4.5, Silverlight 4, Windows Phone 7.5, Mono Android, and Mono iOS. Is there something that I am missing?

Note: This code works in a .Net 4.0 Library which I have made.

Code Examples which return errors:

List<object> set0;
List<object> set1;

if (set0.TrueForAll(obj0 => set1.Exists(obj1 => obj0.Equals(obj1))))
    return true;

if(!(set0.Exists(obj0 => !set1.Exists(obj1 => obj0.Equals(obj1)))))
    return true;

Errors Recived:

Error: 'System.Collections.Generic.List' does not contain a definition for 'Exists' and no extension method 'Exists' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)

Error: 'System.Collections.Generic.List' does not contain a definition for 'TrueForAll' and no extension method 'TrueForAll' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)

You seem to be trying to determine, in a cumbersome way, if set0 is a subset (mathematically) of set1 . If you change your type from List<> to HashSet<> or SortedSet<> , you will get this functionality for free.

Otherwise, consider to use

set0.Except(set1).Any()

from Linq.

I'm not sure which methods exist in the Portable Class Library (PCL), but according to the List<>.Exists doc this method does. And also the Linq methods I mentioned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM