我的问题是:
我有这个代码:
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()
有人可以给我一个解决方案吗?