Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically add values in a 2D array?

Tags:

c#

winforms

I am working with 2D arrays. what I want, is to dynamically add elements in specific columns of my 2D array named symboltable2. I have been doing it as;

result is another 1D array in which there are certain words:

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
    }
} 

but the code above isn't giving me any results... kindly help :(

like image 628
Momo Pomo Avatar asked Mar 04 '26 10:03

Momo Pomo


1 Answers

while implementing arrays you need to give the array's dimension i.e.

string[,] sa = new string[5,15];

or

string[,] sa = new string[listString1.Count, listString2.Count] 

about adding / changing elements to 2D array.. as a simple string array example :

sa[0, 1] = "a";
sa[0, 2] = "b";
sa[1, 0] = "Istanbul / Turkey";
like image 122
sihirbazzz Avatar answered Mar 07 '26 00:03

sihirbazzz