C#利用范集合和文件操作函数显示节目单

C基础算法 cyanprobe 9年前 (2015-11-06) 3061次浏览 已收录 0个评论

实例目的:

将如图domo.TXT文件导入dategridview并显示为效果,注重文件读取时的逻辑运用。
tvdemo

televition.cs文件

 namespace televition
{
 class televition
 {
 public televition()
 {
 }
 public televition(string tetime, int teno, string tename)
 {
 this.Tename = tename;
 this.Teno = teno;
 this.Tetime = tetime;
 }
 public string Tetime { get; set; }
 public int Teno { get; set; }
 public string Tename { get; set; }
 }
}

form1.cs文件:

using System.IO;
namespace televition
{
    public partial class showthis : Form
    {
        List list = new List();
        public showthis()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream("demo.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs, Encoding.Default);
            this.label1.Text = sr.ReadLine();
            sr.ReadLine();
            string[] step = null;
            string content = null;
            while (true)
            {
                content = sr.ReadLine();
                if (content == null || content.Length == 0)
                {
                    break;
                }
                else
                {
                    step = content.Split(Convert.ToChar("\t"));
                    list.Add(new televition()
                    {
                        Tetime = step[0],
                        Tename = step[2],
                        Teno = int.Parse(step[1])
                    }
                    );
                }
            }
            this.dgv.DataSource = list;
            sr.Close();
            fs.Close();
        }

tvde1


CyanProbe , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:C#利用范集合和文件操作函数显示节目单
喜欢 (1)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址