gpt4 book ai didi

c# - 如何在二维数组中动态添加值?

转载 作者:行者123 更新时间:2023-11-30 17:12:19 25 4
gpt4 key购买 nike

我正在使用二维数组。我想要的是在名为 symboltable2 的二维数组的特定列中动态添加元素。我一直这样做;

result 是另一个一维数组,其中有某些单词:

string[,] symboltable2 = new string[,];

if (result.Contains("int")) {
for (int todynamic = 0; todynamic < result.GetLength(0); todynamic++) {
symboltable2[todynamic, 6] = "int";
}
for (int sym2 = 0; i < symboltable1.GetLength(0); sym2++) {
f4.listBox6.Items.Add(symboltable1[sym2, 5]); // To show if the values are added or not
}
}

但是上面的代码没有给我任何结果......请帮忙:(

最佳答案

您需要设置数组的大小。为了公开它,我会使用一个属性并在类构造函数中初始化你的数组,如下所示:

public class MyClass
{
public string[,] symboltable2 { get; set; }

public MyClass()
{
symboltable2 = new string[10,10];
}

// ...

关于c# - 如何在二维数组中动态添加值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10775565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com