当前位置:编程学习 > C#/ASP.NET >>

算法之Linq


            int[] arr = new int[] { 1, -3, 9, 4, 2, 5, 1, -4, 0 };
            var ts = arr.Select(i => new Tuple<int, int>(5 - i, i)).Distinct().
                Where(t => arr.Contains(t.Item1)).Select(t => (t.Item1 <= t.Item2) ? t : new Tuple<int, int>(t.Item2, t.Item1)).Distinct();
            foreach (var t in ts)
            {
                Console.WriteLine("{0} {1}", t.Item1, t.Item2);
            }
            Console.ReadLine();
 
 
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,