最傻的方法也是最有效果的方法。
string[] column = i.Split(new char[] { ','});
int i = 0;
foreach (string j in column)
{
    if (i == 1) frist = j;
    if (i == 2) second = j;
    i++;
    string cell = j;
}循环次数不就是column.Length吗?

解决方案 »

  1.   

    if (i == 0) frist = j;
    if (i == 1) second = j;
      

  2.   

    zswang 说得很对。也可以不用循环:string[] column = i.Split(new char[] { ','});
    first = column[1]
    second = column[2]
      count =  column.Length;
      

  3.   

    string frist = "";//取第一个字符
    string second = "";//取第二个字符
    string[] column = i.Split(new char[] { ','});
    int i = 0;
    foreach (string j in column)
    {
        if (i == 0) frist = j;
        if (i == 1) second = j;
        i++;
        string cell = j;
    }
      

  4.   

    需要知道当前循环次数,为何不用for
      

  5.   

    数组有length属性,就是数组的个数
      

  6.   

    清洁工的就是正解,
    用控制循环次数就用for
      

  7.   

    string frist = "";
    string second = ""; 
    string[] column = i.Split(new char[] { ','}); 
    int i = 0; 
    foreach (string j in column) 

        if (i == 0) frist = j; 
        if (i == 1) second = j; 
        i++; 
        string cell = j; 

      

  8.   

    string frist = "";
    string second = "";
    string[] column = i.Split(new char[] { ','}); 
    int i = 0; 
    foreach (string j in column) 

        if (i == 0) frist = j; 
        if (i == 1) second = j; 
        i++; 
        string cell = j; 

      

  9.   

    知道循环次数的用FOR
    不然就用FOREACH
      

  10.   

    其实我觉得根本不需要循环啊
    你要知道有多少个值
    直接取得数组长度就可以了  column.length 
    还有
    如果去第一和第二个值的话
    string strFirst = column.length > 0 ? column[0] : "";
    string strSecond = column.length > 1 ? column[1] : "";
      

  11.   

    这个问题大家居然也讨论的如此热烈啊,呵呵            string[] column = i.Split(new char[] { ',' });
                if (column.Length>0)
                {
                    first=column[0];
                    if (column.Length>1)
                    {
                        second=column[1];
                    }          
                }