CSharp examples for System:Array Element
Returns a new array consisting of the first elements from the current array. Any excess elements are uninitialized.
using System.Collections.Generic; using System;// w ww. ja v a 2s . c o m public class Main{ /// <summary> /// Returns a new array consisting of the first elements from the current array. Any excess elements are uninitialized. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <param name="count"></param> /// <returns></returns> public static T[] Resize<T>(this T[] self, int count) { var newArr = new T[count]; var len = self.Length < count ? self.Length : count; Array.Copy(self, 0, newArr, 0, len); return newArr; } }