如何定义一个动态的一维数组,可以向该数组中循环添加记录.
并在下面应用该数组>> string[] arrItem
  while (sdr.Read())
        {
            string strItem = sdr["voteItem"].ToString();
        }
............
...........foreach (string s in arrItem)
{
..........
}

解决方案 »

  1.   

    IList<String> arrItem=new List<String>();
    while (sdr.Read()) 
            { 
                string strItem = sdr["voteItem"].ToString();            
                arrItem.Add(strItem); 
            } 
    ............ 
    ........... foreach (string s in arrItem) 

    .......... 
    }
      

  2.   

    你可以使用ArrayList,c#2.0推荐使用List<>
      

  3.   

    arraylist数组列表
    或者他的泛型List<T>
    普通的数组是不可以动态增加的,容量在定义的时候就定死了
      

  4.   

    你可以定义一个数组长度为记录数的count
      

  5.   

    c# 不能创建动态数组,要用的话用ArrayList实现