-4

基于配对从 Arraylist 中删除副本:

如果你开始:

"Rock" "is" "WWE" "Superstar" "How" "is" "pet" "Rock" "is" "WWE" "Superstar" "How" "is" "pet" 

那么输出应该是:

"Rock" "is" "WWE" "Superstar" "How" "is" "pet" 

只有一个副本删除其他匹配对重复。

4

2 回答 2

0

使用 linqLinq.Distinct().ToArray()

于 2012-07-10T16:09:32.640 回答
0

从本质上讲,这将删除每个字符串的第二次出现(我相信这是您需要的):

string[] input = new string[]
{
    "Rock", "is", "WWE", "Superstar", "Rock", "is", "WWE", "Superstar", "How", "is", "pet", "How", "is", "pet" 
};

input.GroupBy(x => x)
     .SelectMany(x => x.Skip(x.Count() / 2))
     .ToList().ForEach(Console.WriteLine);
于 2012-07-10T16:18:06.133 回答