Re: [問題] 實現兩個陣列的聯集程式
看板C_Sharp作者AmosYang (LetMeGoogleThatForYou)時間16年前 (2010/03/18 11:22)推噓3(3推 0噓 4→)留言7則, 3人參與討論串2/2 (看更多)
建議: 先讀完這個
提問的智慧
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
推
03/18 13:32, , 1F
03/18 13:32, 1F
推
03/18 16:35, , 2F
03/18 16:35, 2F
推
03/19 14:51, , 3F
03/19 14:51, 3F
→
03/19 14:52, , 4F
03/19 14:52, 4F
→
03/19 14:53, , 5F
03/19 14:53, 5F
→
03/19 14:53, , 6F
03/19 14:53, 6F
→
03/19 14:53, , 7F
03/19 14:53, 7F
討論串 (同標題文章)