这是我的问题:
我有以下的代码:
static long CountLinesInFile(string f)
{
long count = 0;
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
count++;
}
}
return count;
}
这个问题是关于如何计算文本文件的行数。我遇到的问题是当我尝试以下内容时:
textBox1.Text = CountLinesInFile("test.txt");
我遇到一个错误:
Error 1 Cannot implicitly convert type 'long' to 'string'
这看起来很正常,但我应该如何将它转换为字符串?在Java中,这很简单,只需使用toString()
方法。
有人能给我一个解决方案吗?
.ToString()
方法。 - V4VendettatoString()
与ToString()
)。 - Tim Schmelter