C# 与2 UserProfileValueCollection进行比较的更快方法

C# 与2 UserProfileValueCollection进行比较的更快方法,c#,.net,algorithm,sharepoint,optimization,C#,.net,Algorithm,Sharepoint,Optimization,用户1的兴趣(“篮球”、“曲棍球”、“棒球”) 用户2的兴趣(“拳击”、“篮球”) 我希望我能用一种更快的方式进行比较,因为我很有可能会比较200多个不同兴趣的用户。所以我最终会这么做 ///Search common interest among the members of the group foreach(SPUser user in oweb.Groups[0].Users){ if(CurrentlyLoggedInUser have common interest with

用户1的兴趣(“篮球”、“曲棍球”、“棒球”)

用户2的兴趣(“拳击”、“篮球”)

我希望我能用一种更快的方式进行比较,因为我很有可能会比较200多个不同兴趣的用户。所以我最终会这么做

///Search common interest among the members of the group
foreach(SPUser user in oweb.Groups[0].Users){
    if(CurrentlyLoggedInUser have common interest with user){
        ///do the necessary logic here
    }
}

比较两个无序集合的通用方法(使用Linq):

bool比较集合(IEnumerable a、IEnumerable b)
{
//如果您知道他们实现了Count而不是Count()
//然后使用正确的类型
如果(a.Count()!=b.Count())
返回false;
var hs=新哈希集(a);
返回b.All(hs.Contains);
}
///Search common interest among the members of the group
foreach(SPUser user in oweb.Groups[0].Users){
    if(CurrentlyLoggedInUser have common interest with user){
        ///do the necessary logic here
    }
}
bool CompareStringCollections(IEnumerable<string> a, IEnumerable<string> b) 
{
   // If you know they implement the Count instead of Count() 
   // use then the right type
   if ( a.Count() != b.Count() )
       return false;
   var hs = new HashSet(a);
   return b.All(hs.Contains);
}