首页 > 编程 > C# > 正文

将数组中指定数量的元素移动数组后面的实现代码

2020-01-24 03:13:39
字体:
来源:转载
供稿:网友
如下所示:
复制代码 代码如下:

        static void Main()
        {
            int[] array = { 1, 2, 3, 4, 5, 6, 7 };
            MoveNumberArrayToEnd(array, 3);
        }
        static void MoveNumberArrayToEnd<T>(IList<T> arrayList, int num)
        {
            if (arrayList.Count < = 0 || arrayList.Count < num)
            {
                throw new RankException();
            }
            var query = (from number in arrayList
                         orderby number descending
                         select number).Take(arrayList.Count - num).Concat(arrayList.Take(num));
            query.ToList().ForEach(q => Console.WriteLine("{0}", q));
        }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表