日期:2010-01-01  浏览次数:20651 次

编写一个类实现数组元素的交集和并集运算
要求:
      1、要有构造函数对数组初始化
      2、包含交集和并集两个单独的方法
      3、要有一个打印数组元素的方法
      4、编写一个测试类测试数组
      5、要求控制台中要分别输出两个原数组以及将交集和并集运算结果输出

代码:

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Text; 
  4. namespace ConsoleApplication4 
  5. { 
  6.     class Program 
  7.     { 
  8.         static void Main(string[] args) 
  9.         { 
  10.             int[] A = { 65, 42, 11, 8, -4}; 
  11.             int[] B = { 2,90, 2, 11, 33, 8}; 
  12.             Console.WriteLine("合并前的元素集A:"); 
  13.             foreach (int x in A) 
  14.             { 
  15.                 Console.Write("{0}  ", x); 
  16.             } 
  17.             Console.WriteLine("\n合并前的元素集B:"); 
  18.             foreach (int x in B) 
  19.             { 
  20.                 Console.Write("{0}  ", x); 
  21.             } 
  22.             Set s = new Set(A, B); 
  23.             if (s.SetA != null && s.SetB != <