标题:C#编译出错,不知哪里的问题
取消只看楼主
yuma
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:银河系
等 级:贵宾
威 望:33
帖 子:1883
专家分:2904
注 册:2009-12-22
结帖率:89.13%
 问题点数:0 回复次数:0 
C#编译出错,不知哪里的问题
C#  读文件

程序代码:
using System;
using namespace FileApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // 创建一个 StreamReader 的实例来读取文件 
                // using 语句也能关闭 StreamReader
                using (StreamReader sr = new StreamReader("names.txt"))
                {
                    string line;

                    // 从文件读取并显示行,直到文件的末尾 
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                }
            }
            catch (Exception e)
            {
                // 向用户显示出错消息
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
    }
}
搜索更多相关主题的帖子: 文件 Console using 出错 C# 
2021-02-27 20:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-504971-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016631 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved