两个集合的交集,并集,差集如何计算

string[] arr1 = { "445345", "fsdfsdf", "423423", "123" };
            string[] arr2 = { "123", "Fsdfsdf", "3243", "324234" };
            var query1 = arr1.Union(arr2);//两个集合的并集
            var i = 1;
            Console.WriteLine("输出并集");
            foreach (string item in query1)
            {
                Console.WriteLine(i + ":" + item);
                i++;
            }

            var query2 = arr1.Intersect(arr2);
            i = 1;
            Console.WriteLine("输出交集");
            foreach (string item in query2)
            {
                Console.WriteLine(i + ":" + item);
                i++;
            }

            var query3 = arr1.Except(arr2);
            i = 1;
            Console.WriteLine("arr1有的,arr2没有的");
            foreach (string item in query3)
            {
                Console.WriteLine(i + ":" + item);
                i++;
            }

            var query4 = arr2.Except(arr1);
            i = 1;
            Console.WriteLine("arr2有的,arr1没有的");

            foreach (string item in query4)
            {
                Console.WriteLine(i + ":" + item);
                i++;
            }

你可能感兴趣的:(.net,Linq)