本帖最后由 ScholarLin 于 2015-02-07 15:56:12 编辑

解决方案 »

  1.   

     where T : class 去掉
    all = StaticClass.MergeArray<int>(a, b, c);
      

  2.   

    看看人家 .net framework 源代码是怎样合并的:        public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
            {
                if (first == null)
                {
                    throw Error.ArgumentNull("first");
                }
                if (second == null)
                {
                    throw Error.ArgumentNull("second");
                }
                return Enumerable.ConcatIterator<TSource>(first, second);
            }
            private static IEnumerable<TSource> ConcatIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second)
            {
                foreach (TSource tSource in first)
                {
                    yield return tSource;
                }
                foreach (TSource tSource1 in second)
                {
                    yield return tSource1;
                }
            }
      

  3.   

    调用 Linq 时,就是这样的:int[] a = new int[] { 1, 2, 3 }
        , b = new int[] { 4, 5, 6 }
        , c = new int[] { 7, 8, 9 };
    var all = a.Concat(b).Concat(c).ToArray();
      

  4.   


     public static class ArrayTest<T>
        {
            /// <summary>
            /// 合并数组
            /// </summary>
            /// <param name="args"></param>
            /// <returns></returns>
            public static T[] MerageArr(params T[][] args)
            {
                int arraryLength = 0, len = 0;
                foreach (var item in args)
                {
                    arraryLength += item.Length;
                }            T[] result = new T[arraryLength];
                foreach (var item in args)
                {
                    item.CopyTo(result, len);
                    len += item.Length;
                }
                return result;
            }       
        }
    调用            int[] a = new int[3] { 1, 2, 3 };
                int[] b = new int[3] { 4, 5, 6 };
                int[] c = ArrayTest<int>.MerageArr(a, b);
                StringBuilder sb = new StringBuilder("合并后的数组:");
                foreach (int i in c)
                {
                    sb.AppendFormat(",{0}", i);
                }
                MessageBox.Show(sb.ToString());