我以双打数组的形式从旧式ActiveX中提取数据.我最初并不知道我将实际检索的样本的最终数量.
将这些数组连接到系统中时,将这些数组连接在一起的最有效方法是什么?
是否有更高效的连接二维数组的方法?
static void Main(string[] args)
{
int[][] array1 = { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } } ;
int[][] array2 = { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } };
int[][] array3 = Concat(array1, array2);
}
private static int[][] Concat(int[][] array1, int[][] array2)
{
int array1Length = array1.Length;
int array2Length = …Run Code Online (Sandbox Code Playgroud) 如何在C#中使用两个(或更多)其他数组巧妙地初始化数组?
double[] d1 = new double[5];
double[] d2 = new double[3];
double[] dTotal = new double[8]; // I need this to be {d1 then d2}
Run Code Online (Sandbox Code Playgroud)另一个问题:如何有效地连接C#数组?
我有以下数组:
int[] numbers;
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以为数组添加数字?我没有找到连接2个数组的扩展方法,我想做类似的事情:
numbers = numbers.Concat(new[] { valueToAdd });
Run Code Online (Sandbox Code Playgroud) string[] filesHD = Directory.GetFiles(dirPath, filepattern1);
string[] filesDT = Directory.GetFiles(dirPath, filepattern2);
string[] filesTD = Directory.GetFiles(dirPath, filepattern3);
Run Code Online (Sandbox Code Playgroud)
我的filesHD[]数组包含2个文件.filesDT[]包含2个文件,filesTD[]还包含2个文件.
我想创建一个字符串数组,它包含所有的6个文件filesHD,filesDT,filesTD.
string[] Allfiles = new string [filesHD + filesDT + filesTD]
Run Code Online (Sandbox Code Playgroud) 可能重复:
在.NET中合并两个数组
如何在C#中连接两个数组?
我怎么能合并两个string[]变量?
例:
string[] x = new string[] { "apple", "soup", "wizard" };
string[] y = new string[] { Q.displayName, Q.ID.toString(), "no more cheese" };
Run Code Online (Sandbox Code Playgroud)
我想添加这两个,所以内容x是:{"apple", "soup", "wizard",Q.displayName, Q.ID.toString(), "no more cheese"};按顺序.这可能吗?如果结果必须进入一个很好的新字符串数组; 我只是想知道如何实现它.
我正在尝试将2个新数组项添加到现有字符串数组中.我取得了成果,但我确信这不是正确的方法.
如何将项添加到字符串数组中.
string[] sg = {"x", "y" };
string[] newSg = {"z", "w"};
string[] updatedSg = new string[sg.Length+newSg.Length];
for (int i = 0; i < sg.Length; i++)
{
updatedSg[i] = sg[i];
}
for (int i = 0; i < newSg.Length; i++)
{
updatedSg[sg.Length+i] = newSg[i];
}
Run Code Online (Sandbox Code Playgroud) 在C#中,我有三个数组,string[] array12和3,它们都有不同的值.我很乐意在php中做我能做的事情:
$array = array();
$array[] .= 'some value';
什么是在C#中这样做的相同方式?
我试图选择一组值,每个方法返回一个字符串数组,我试图将其放入主要的字符串数组中.这是代码:
string[] array = { MethodA1(), MethodA2(), MethodA3() };
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建string []数组,只有一个项目.这有效:(但它只允许用户显示/选择一个值)
string[] array = MethodA1();
Run Code Online (Sandbox Code Playgroud)
任何人都可以想到一种允许多个方法返回数组的方法吗?