# 两个数组比较，去掉重复的数据后生成第三个数组，这个怎么实现？

0
[已解决问题] 解决于 2012-03-13 08:59

string arr1 ["11","33","2","5555","9999"]

string arr2 ["11","9999"]

kdkler | 初学一级 | 园豆：154

1
`string[] arr1={"11","33","2","5555","9999","10"};            string[] arr2={"11","9999","1","2"};            List<string> arr=new List<string>();            foreach(string c1 in arr1)            {                arr.Add(c1);            }            foreach (string c2 in arr2)            {                if (!arr1.Contains(c2))                {                    arr.Add(c2);                }            }            foreach(string c3 in arr)            {                Console.WriteLine(c3);            }            Console.ReadLine();`
ForEvErNoMe | 菜鸟二级 |园豆：207 | 2011-11-10 19:45

0

class Program
{
static void Main(string[] args)
{
string[] arr1 = { "11", "33", "2", "5555", "9999" };
string[] arr2 = { "11", "9999" };
string[] arr3 = null;
List<string> list = new List<string>();
IEnumerable<string> arrs = arr1.Except(arr2);
foreach (string arr in arrs)
{
}
arr3 = list.ToArray();
foreach (string a in arr3)
{
Console.Write("{0} ", a);
}
}
}

0

`string[] arr1 = { "11", "33", "2", "5555", "9999" };string[] arr2 = { "11", "9999" };string[] arr3 = arr1.Except(arr2).ToArray();`

`string[] arr1 = { "11", "33", "2", "5555", "9999" };string[] arr2 = { "11", "9999","44" };`
`　　我要的到string[] arr3={"33","2","44","5555"}?`
`string[] arr3=arr1.Except(arr2).ToArray();还行吗？ 求解释！！！`

@Ｏ|(: 如果你想写的很酷而不是很迫切的要高性能，那么依然可以一句话：

`string[] arr3 = arr1.Union(arr2).Except(arr1.Intersect(arr2)).ToArray();`

@水牛刀刀: o thak you!~.~

0

您需要登录以后才能回答，未注册用户请先注册