C# 查找两个列表之间的差集(LINQ)

使用LinQ找出两集合的差集

 

 1         static void FindArrayDifferent()
 2         {
 3             // Create the IEnumerable data sources.
 4             string[] names1 = System.IO.File.ReadAllLines(@"file1.txt");
 5             string[] names2 = System.IO.File.ReadAllLines(@"file2.txt");
 6 
 7             IEnumerable<string> differenceQuery =
 8               names1.Except(names2);
 9 
10             // Execute the query.
11             Console.WriteLine("The following lines are in names1.txt but not names2.txt");
12             foreach (string s in differenceQuery)
13                 Console.WriteLine(s);
14         }

 

posted @ 2012-03-12 17:58  丁守庆  阅读(1045)  评论(0编辑  收藏  举报
专业成就价值