当前位置: 编程技术>.net/c#/asp.net
将数组中指定数量的元素移动数组后面的实现代码
来源: 互联网 发布时间:2014-10-21
本文导语: 如下所示: 代码如下: static void Main() { int[] array = { 1, 2, 3, 4, 5, 6, 7 }; MoveNumberArrayToEnd(array, 3); } static void MoveNumberArrayToEnd(IList arrayList, int num) ...
如下所示:
static void Main()
{
int[] array = { 1, 2, 3, 4, 5, 6, 7 };
MoveNumberArrayToEnd(array, 3);
}
static void MoveNumberArrayToEnd(IList 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));
}
代码如下:
static void Main()
{
int[] array = { 1, 2, 3, 4, 5, 6, 7 };
MoveNumberArrayToEnd(array, 3);
}
static void MoveNumberArrayToEnd(IList 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));
}