加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#将long转换为字符串

发布时间:2020-12-15 07:40:26 所属栏目:百科 来源:网络整理
导读:我的问题在于: 我有这个代码: static long CountLinesInFile(string f){ long count = 0; using (StreamReader r = new StreamReader(f)) { string line; while ((line = r.ReadLine()) != null) { count++; } } return count;} 这会计算文本文件的行数.我
我的问题在于:

我有这个代码:

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()方法:
textBox1.Text = CountLinesInFile("test.txt").ToString();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读