日期:2014-05-18  浏览次数:21054 次

C#如何取得交集数据?
1.txt的内容为:
888888
777777
666666
555555
...
..
.
2.txt的内容为:
123456
888888
879789
555555
...
..
.
----------------------
分别读取2个TXT文件,取得她们的交集,接着输出到C盘,请问如何做?

------解决方案--------------------
贴完整的
C# code

 string[] arr1 = File.ReadAllLines(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
 string[] arr2 = File.ReadAllLines(@"C:\3.txt", Encoding.GetEncoding("GB2312"));
string[] arr0 = (from str1 in arr1 select str1).Intersect(from str2 in arr2 select str2).ToArray();
 File.WriteAllLines(@"C:\2.txt",arr0);