OK,算法如下:
static void Main(){
int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Resize<int>(ref a, x => x < 7);
}
static void Resize<T>(ref T[] source, Predicate<T> predicate){
if (source == null || predicate == null)
throw new ArgumentNullException("source");
ICollection<T> result = new List<T>();
foreach (var item in source){
if (predicate(item)) result.Add(item);
}
Array.Resize<T>(ref source, result.Count);
result.ToArray<T>().CopyTo(source, 0);
}