string[] al = new string[10];
            foreach (int st in al)
                al[st] = "待定";
出错....

解决方案 »

  1.   

    MS你错的还不是少        for (int st = 0; st < al.Length; st++)
            {
                al[st] = "待定";
            }
      

  2.   


    al 是string类型的数组,每一个元素都为string
    你用int 来循环遍历,肯定错了。
     string[] al = new string[10];
                List<int> ls = new List<int>();
                for(int i=0;i<10;i++)
                {
                 ls.Add(i);
                }
                foreach (int st in ls)
                {
                    al[st] = st.ToString()+"AAA";
                }
    可以参考
      

  3.   

    st 就是值了,不是索引。
    为什么不用forstring[] al = new string[10];
    for (int st = 0;i<al.Length;++st )
       al[st] = "待定";
      

  4.   

    foreach的话
    你可以理解为只读。
    具体的看下MSDN吧
      

  5.   

    用for赋值
    foreach是读取数据
     foreach(string str in al)
    {
         // 
    }
      

  6.   

    你是string型的数组,怎么用int型去遍历?
    楼主,你还根本不懂foreach的用法吧
      

  7.   

    al 是个数组,st 是 int 类型,当然会出错,你要把数组的值都赋为“待定”吗?
    如果是这样的话,可以用 一个for循环实现
    string[] al = new string[10];
                for (int i = 0; i < al.Length; i++)
                {
                    al[i] = "待定"; 
                }
      

  8.   

    我觉得楼主可能是想这样            string[] al = new string[10];
                foreach (string st in al)
                {
                    st = "待定";
                }
    但是st是foreach的一个迭代变量,不能给他赋值。所以还是用1楼的办法吧,不要用foreach了
      

  9.   

        string[] al = new string[10];
          for (int st=0;st<al.Length ;st++)
            {
                al[st] = "OK"+st.ToString();
            }
    你上面的例子会提示,类型不对的.int 型怎么能和string 型 用in关键字呢.改用for语句吧.