User1的兴趣('篮球','曲棍球','棒球')
User2的兴趣('拳击','篮球')
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
}
}
答案 0 :(得分:0)
比较两个无序集合的一般方法(使用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);
}