将数组中指定数量的元素移动数组后面的实现代码
发布时间:2016-12-28 来源:查字典编辑
摘要:如下所示:复制代码代码如下:staticvoidMain(){int[]array={1,2,3,4,5,6,7};MoveNumberAr...
如下所示:
复制代码 代码如下:
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));
}