char[] tmp = new char[8];
int loop = tmp.Length;这样取出loop是8  我想取出tmp实际字符个数

解决方案 »

  1.   

    int length = (new string(tmp)).Length();
      

  2.   

    int length = (new string(tmp)).Length;
    没有括号
      

  3.   

    for (int i=0; i<tmp.length;i++)
        loop=loop+tmp[i].length;
      

  4.   

    那样的话,搂主似乎只能循环一次:
    StringBuilder sb = new StringBuilder();
    for (int index = 0; index < tmp.Length; index++)
    {
        char ch = tmp[index];
        if (ch != '\0')
            sb.Append(ch);
    }
    string realString = sb.ToString();
      

  5.   

    int realLength = sb.Length;
      

  6.   

    测试了一把,搂主确实得循环一次,因为char这种对象不可能为null的,缺省就是'\0'
      

  7.   

    谢谢 net5i测试通过,结帖!