C#中的数组串联(Array concatenation in C#)
我如何在C#中用两个(或更多)其他数组巧妙地初始化一个数组?
double[] d1 = new double[5]; double[] d2 = new double[3]; double[] dTotal = new double[8]; // I need this to be {d1 then d2}另一个问题:我如何高效地连接C#数组?
How do I smartly initialize an Array with two (or more) other arrays in C#?
double[] d1 = new double[5]; double[] d2 = new double[3]; double[] dTotal = new double[8]; // I need this to be {d1 then d2}Another question: How do I concatenate C# arrays efficiently?
最满意答案
您可以使用CopyTo :
double[] d1 = new double[5]; double[] d2 = new double[3]; double[] dTotal = new double[d1.Length + d2.Length]; d1.CopyTo(dTotal, 0); d2.CopyTo(dTotal, d1.Length);You could use CopyTo:
double[] d1 = new double[5]; double[] d2 = new double[3]; double[] dTotal = new double[d1.Length + d2.Length]; d1.CopyTo(dTotal, 0); d2.CopyTo(dTotal, d1.Length);更多推荐
发布评论