[C#] Dynamic array using ArrayList
ArrayList class is provided in C# for management dynamic element. ArrayList class can be handled like dynamic array, because ArrayList elements can be accessed by index.

Code example


private void button6_Click(object sender, EventArgs e)
{
  ArrayList data = new ArrayList();
  data.Add(10);
  data.Add(8);
  data.Add(6);
  data.Add(4);
  data.Add(2);

  for (int i=0; i<data.Count; i++){
    textBox1.Text += Convert.ToString((int)data[i])+"\t";
  }
}

Commentary

ArrayList data = new ArrayList();
Create ArrayList instance to define ArrayList class value named "data".
data.Add(10);
Insert value into "data".

Description for access to ArrayList element is below.
data[i]
"data[i]" type is object, type cast is needed to get value from "data". When "data" is inserted int value, code for get value is below.
(int)data[i]

Register date :2011-10-21    Last update :2017-01-17
JapaneseEnglish
プライバシー    iPentecについて
iPentec all rights reserverd. (ISDC)