本来想了解一下扩展方法,但是看到文库中的实例明显有问题,特来提问
泛型对象T 如何使用Length 属性?
可以像类中一样加继承于某某类的约束吗?
public static class testEx
{
public static int ToInt32haha(this string str)
{
return Int32.Parse(str);
}
public static T[] Slice<T>(this T source, int index, int count)
{
if (index < 0 || count < 0 || index + count > source.Length)
{
throw new ArgumentException();
}
T[] result = new T[count];
Array.Copy(source, index, result, 0, count);
return result;
}
}