看板 C_Sharp 關於我們 聯絡資訊
建議: 先讀完這個 提問的智慧 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
dk3208:學了LINQ之後世界都不一樣了...XD 03/18 13:32
chancewen:LINQ 學習中+1 03/18 16:35
MMAXo:直接使用的話...... 03/19 14:51
MMAXo:string[] A = new string[A的個數]; 03/19 14:52
MMAXo:string[] B = new string[B的個數]; 03/19 14:53
MMAXo:string[] C = A.Union<string>(B).ToArray<string>(); 03/19 14:53
MMAXo:C 就是結果 @@ 03/19 14:53