3
Answers

2-d arrays inside an ArrayList

j_sen21

j_sen21

17y
7.5k
1

Hello, I created 2-d array and place it in a ArrayList.

When I read out from it, it only prints the last item, the number of times I placed an item inside the arrayList.

ArrayList configureList = new ArrayList();

Object[,] configureValues = new Object[2, 2];

value insert-------------------------

configureValues[0, 0] = "this";

configureValues[0, 1] = 1;

configureList.Add(configureValues);

configureValues[0, 0] = "is";

configureValues[0, 1] = 2;

configureList.Add(configureValues);

configureValues[0, 0] = "fun";

configureValues[0, 1] = 3;

configureList.Add(configureValues);

extraction----------------------------------

string tempo = "";

for (int i = 0; i < configureList.Count; i++)

{

object[,] retrieved = (object[,])configureList[i];

String ct = (String)retrieved[0, 0];

int temp = (int)retrieved[0, 1];

 

tempo = tempo + ct + "\n";

}

MessageBox.Show("tempo = " + tempo);

 

-----------------------prints

fun

fun

fun

 

Help, Thanks.

 

,

 

 

 

Answers (3)