/* ----------------------------------------------------------
* 文件名称:Utils.cs
*
* 作者:秦建辉
*
* QQ:36748897
*
* 博客:http://www.firstsolver.com/wordpress/
*
* 开发环境:
* Visual Studio V2015
* .NET Framework 4 Client Profile
*
* 版本历史:
* V1.0 2016年05月20日
* 一种提取子数组的简洁高效方法
* ---------------------------------------------------------- */
using System.Linq;
namespace Com.FirstSolver.Toolkit
{
public static class Utils
{
///
/// 泛型扩展方法:提取子数组
///
/// 数组类型
/// 源数据
/// 起始位置
/// 数据长度
/// 子数组
public static TSource[] CopyRange(this TSource[] source, int startIndex, int count)
{
if (startIndex == 0)
return source.Take(count).ToArray();
else if (startIndex + count == source.Length)
return source.Skip(startIndex).ToArray();
else
return source.Skip(startIndex).Take(count).ToArray();
}
}
}