StreamReader sr=null;
long total=0;
sr=File.OpenText("myfile.txt");
Char[] buf=new Char[sr.BaseStream.Length];
sr.ReadBlock(buf,0,sr.BaseStream.Length-1);
sr.Close();
foreach(Char ch in buf)
{
    if(ch=='x') total+=1;
}
MessageBox.Show(total.ToString());在第5行,提示出错:“buf”表示“变量”,此处应为“方法”应该如何改正?

解决方案 »

  1.   

    StreamReader sr=null;
    long total=0;
    sr=File.OpenText("myfile.txt");
    char[] buf=new char[sr.BaseStream.Length];//应该为char,不是Char
    sr.ReadBlock(buf,0,Convert.ToInt32(sr.BaseStream.Length - 1));
    sr.Close();
    foreach(char ch in buf)
    {
        if(ch=='x') total+=1;
    }
      

  2.   

    执行了一下。。真的没错。。
    不过total是0。。
      

  3.   

    char Char  不是这个问题,换成char也一样出错,关键在第5行
      

  4.   

    在第5行,类型要转换一下.谢谢大虾了.不过为什么写成Char会没事呢?