簡體   English   中英

比較2 UserProfileValueCollection的更快方法

[英]faster way to compare to 2 UserProfileValueCollection

用戶1的興趣(“籃球”,“曲棍球”,“棒球”)

用戶2的興趣(“拳擊”,“籃球”)

using(SPSite site = new SPSite(SPContext.Current.Web.Url)){
    using(SPWeb web = site.OpenWeb()){
        ServerContext oContext = ServerContext.GetContext(site);
        UserProfileManager upManager = new UserProfileManager(oContext); 
        UserProfile User1Profile = upManager.GetUserProfile(user1.LoginName); // user1 is SPUser
        UserProfile User2Profile = upManager.GetUserProfile(user2.LoginName); // user2 is SPUser

        /// Faster way to check if the interest of User1 have something common in User2
        /// In the interest list above user1 and user2 have a common interest on Basketball
        /// How will I do this checking. I prefer a faster approach like the  Array.IndexOf
        /// but this can't be done on the UserProfileValueCollection.

    }
}

我希望我可以使用更快的比較方法,因為我很有可能會比較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 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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM