作者AmosYang (LetMeGoogleThatForYou)
看板C_Sharp
标题Re: [问题] 实现两个阵列的联集程式
时间Thu Mar 18 11:22:47 2010
建议: 先读完这个
提问的智慧
http://mis.ndhu.edu.tw/docu/question.htm
※ 引述《mopa (不要留下遗憾)》之铭言:
: 有两个字串阵列A[],B[]
: 想写一个取其联集的程式
: C[] = A[] 联集 B[]
: 要如何下手呢?
101 LINQ Samples: Set Operators
http://msdn.microsoft.com/en-us/vcsharp/aa336761.aspx
Union - 1
This sample uses Union to create one sequence that contains the unique
values from both arrays.
public void Linq48()
{
int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
int[] numbersB = { 1, 3, 5, 7, 8 };
var uniqueNumbers = numbersA.Union(numbersB);
Console.WriteLine("Unique numbers from both arrays:");
foreach (var n in uniqueNumbers)
{
Console.WriteLine(n);
}
}
Result
Unique numbers from both arrays:
0
2
4
5
6
8
9
1
3
7
--
"Mr. Data, can you show me how to parse this XML?"
"Certainly, sir.
Let me google that for you."
-- StarTrek, the Next Gen. 《Back to 2009》 (误)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 65.87.177.87
1F:推 dk3208:学了LINQ之後世界都不一样了...XD 03/18 13:32
2F:推 chancewen:LINQ 学习中+1 03/18 16:35
3F:推 MMAXo:直接使用的话...... 03/19 14:51
4F:→ MMAXo:string[] A = new string[A的个数]; 03/19 14:52
5F:→ MMAXo:string[] B = new string[B的个数]; 03/19 14:53
6F:→ MMAXo:string[] C = A.Union<string>(B).ToArray<string>(); 03/19 14:53
7F:→ MMAXo:C 就是结果 @@ 03/19 14:53