datagridview问题
【datagridview中】ID NAME VALUE
1 兔子 3
2 兔子 5
3 猫 2
4 猫 4
5 猫 1
6 狗 5
... ... ...
【问题】我想把属于一类的值放到一个数组里面,应该怎么做例如:[3,5],[2,4,1][5]
int n = this.dataGridView1.Rows.Count;
ArrayList nums = new ArrayList();
for (int i = 0; i < n;i++ )
{
String stringValue = this.dataGridView1.Rows[i].Cells[1].Value as string;
switch (stringValue)
{
case "兔子":
double a = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
nums[i] = a; 【报错】索引超出范围。必须为非负值并小于集合大小。参数名: index
break;
case "猫":
double b = Convert.ToDouble(dataGridView1.Rows[i].Cells[2]);
nums[i] = b;
break;
case "狗":
double c = Convert.ToDouble(dataGridView1.Rows[i].Cells[2]);
nums[i] = c;
break;
具体应该怎么改,请详细解释下,谢谢!