8. 集合操作符—【LINQ标准查询操作符】

public class Distinct_LINQ
    {
        public static void Distinct_Print()
        {
            List<int> quantity = new List<int> { 1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10 };
            IEnumerable<int> val = quantity.Distinct();
            foreach (int i in val)
            {
                Console.WriteLine(i.ToString());
            }            
        }

        public static void Union_Print()
        {
            int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] numbers2 = { 11, 12, 13, 14, 15, 16, 17, 18 };
            IEnumerable<int> union = numbers1.Union(numbers2);
            foreach (int i in union)
            {
                Console.WriteLine(i.ToString());
            }
        }

        public static void Intersect_Print()
        {
            int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] numbers2 = { 1, 2, 13, 14, 5, 16, 7, 18 };
            IEnumerable<int> intersect = numbers1.Intersect(numbers2);
            foreach (int i in intersect)
            {
                Console.WriteLine(i.ToString());
            }
        }

        public static void Except_Print()
        {
            int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] numbers2 = { 1, 2, 13, 14, 5, 16, 7, 18 };
            IEnumerable<int> except = numbers1.Except(numbers2);
            foreach (int i in except)
            {
                Console.WriteLine(i.ToString());
            }
        }
    }
posted @ 2010-04-17 21:59  CityWalker  阅读(309)  评论(0编辑  收藏  举报
天天来