Let's say
string[] admins = "aron, mike, bob";
string[] users = "mike, katie, sarah";
How can I take the users and strip out anyone from the admins.
the result should be "katie, sarah"; (mike was removed)
Is there a nice Linq way to do this开发者_Python百科?
// as you may know, this is the right method to declare arrays
string[] admins = {"aron", "mike", "bob"};
string[] users = {"mike", "katie", "sarah"};
// use "Except"
var exceptAdmins = users.Except( admins );
users.Except(admins);
See more set operations:
http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx
The easiest would to be use IEnumerable<T>.Except
:
var nonAdmins = users.Except(admins);
精彩评论