有一个数组string[] ModelName = new string[3];数组ModelName大小固定
怎么才能用代码向数组中添加项啊?

解决方案 »

  1.   

    string[] ModelName ={"a","b","c"}
      

  2.   

    方式有两个,一个是在定义的时候:
    string[] ModelName = new string[3]
    {
    "value1","value2","value3"
    }
    第二个是用索引:
    [code=C#]string[] ModelName = new string[3]
    ModelName[0]="value1";
    ModelName[1]="value2";
    ModelName[2]="value3";
    [code]
      

  3.   

    string[] ModelName = new string[3]{"a","b","c"};动态赋值:ModelName[0]="Tom";//给第0个元素赋值
      

  4.   

    string[] ModelName = new string[3]{"a","b","c"};
      

  5.   

    string[] ModelName = new string[3];
    for (int i = 0; i < ModelName.Length; i++)
    {
        //ModelName.SetValue(DateTime.Now.Ticks, i);
        //或者
        ModelName[i] = DateTime.Now.Ticks.ToString();
    }
      

  6.   

      List<string> list = new List<string>();
            list.Add("1");
            list.Add("2");
            list.Add("3");