[英]Read text file line by line in C#
I am trying to read a text file line by line inside a textbox, but it returns only the word "!MANAGERS" in the textbox.我试图在文本框中逐行读取文本文件,但它只返回文本框中的“!MANAGERS”一词。
My text file is:我的文本文件是:
!MANAGERS
NUMBERS = 6
ADMIN = 1
!INFORMATIONS
741852:PAULO MARCO:MANAGER:TEAM
My code to get the file is:我获取文件的代码是:
public static string GetFile () {
string filepath = @"C:\Files\projectmanager.txt";
StreamReader reader = new StreamReader (filepath);
string lines = reader.ReadLine ();
var list = new List<string> ();
list.Add (lines);
string[] liness = list.ToArray ();
foreach (string line in liness) {
return line;
}
return "ERROR";
}
My textbox code is:我的文本框代码是:
String filetext = ToolLibrary.FileSystem.GetFile();
textbox1.Text = filetext;
You can simply write你可以简单地写
textbox1.Text = File.ReadAllText(filepath);
Also, set the Multiline
property of the text box to true
.此外,将文本框的
Multiline
属性设置为true
。 (You can do so in the properties window.) (您可以在属性窗口中执行此操作。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.