j_sen21

j_sen21

  • NA
  • 57
  • 0

2-d arrays inside an ArrayList

Nov 1 2007 4:47 PM

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)