Read each line in file and put each line into a string

前端 未结 1 1168
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 09:54

I have a text file that I want to read in and put each line from the file into its own string. So the file will have 4 lines:

2017-01-20
05:59:30

相关标签:
1条回答
  • 2021-01-28 10:16

    You may want to consider using the File.ReadAllLines() method which will store each line of your file into an array :

    var lines = File.ReadAllLines(FileName);
    

    You could then access each of your properties by their indices as needed :

    string Date = lines[0];
    string Time = lines[1];
    string Phone = lines[2];
    string JobNo = lines[3];
    string Name = lines[4];
    
    0 讨论(0)
提交回复
热议问题