当前位置:编程学习 > C#/ASP.NET >>

请帮忙解释下文件读取的代码?




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;//文件读写用

namespace WFMStudentManager
{
    public partial class frmScoreSearch : Form
    {
        public ClsStudent[] arrayStu = new ClsStudent[20];
        public clsScore[] arrayScore = new clsScore[30];
        public clsCourse[] arrayCur = new clsCourse[20];
        public int intCurrentAddScoreTotal = 0;

        public frmScoreSearch()
        {
            InitializeComponent();
        }

        private void frmScoreSearch_Load(object sender, EventArgs e)
        {
            string strFilePath = Directory.GetCurrentDirectory();
            string strFileName = strFilePath + "\\score.txt";
            FileStream txtFile = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
            StreamReader txtfileSr = new StreamReader(txtFile);
            
string strLine = txtfileSr.ReadLine();  //定义了strLine,有什么用?
            
for (int i = 0; strLine != null; i++)
            {
                arrayScore[i]= new clsScore ();
                arrayScore[i].CourseName = strLine;//同样是读取一个txt文件中的内容,这里为什么用:strLine?下面的却改成:txtfileSr.ReadLine();?
                arrayScore[i].CourseNum = txtfileSr.ReadLine();
                arrayScore[i].StuNum = txtfileSr.ReadLine();
                arrayScore[i].StuName = txtfileSr.ReadLine();
                arrayScore[i].Score = float.Parse(txtfileSr.ReadLine());

                strLine = txtfileSr.ReadLine();//这一句是什么意思?把什么赋给strLine?
            }
            txtfileSr.Close();
            txtFile.Close();

            strFileName = strFilePath + "\\course.txt";
            txtFile = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
            txtfileSr = new StreamReader(txtFile);
            
strLine = txtfileSr.ReadLine();
--------------------编程问答-------------------- 因为循环条件是strLine为空时跳出循环,strLine保存的是从文本中读取出来的一行数据 --------------------编程问答-------------------- 逐行读取到变量strLine, 直到为strLine为空(即strLine为空时, 文件全部行已经读完) --------------------编程问答--------------------
引用 2 楼  的回复:
逐行读取到变量strLine, 直到为strLine为空(即strLine为空时, 文件全部行已经读完)


多谢提醒!
arrayScore[i].CourseName = strLine;//同样是读取一个txt文件中的内容,这里为什么用:strLine?下面的却改成:txtfileSr.ReadLine();?
--------------------编程问答-------------------- strLine = txtfileSr.ReadLine();//这一句是什么意思?把什么赋给strLine?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,