开发者

C# Linq String[] list minus from String[] list

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜