简体   繁体   中英

How to get items from an array and display them in a textbox;

string[] files = Directory.GetFiles("C:/Users/ME/Desktop/items/", ".txt", SearchOption.AllDirectories);

如何在我创建的文本框中显示返回的结果?

textbox1.Text = string.Join(Environment.NewLine, files);

这内部使用StringBuilder或等效项来获得最佳性能和堆碎片防护

foreach (string file in files) {
  textbox1.Text += file + Environment.NewLine;
}
System.Text.StringBuilder sbText = new System.Text.StringBuilder(10000);

foreach (string sFile in files) {
  sbText.AppendLine(sFile);
}

TextBox1.Text = sbText.ToString();

Provided this is a multi-line textbox:

foreach (string file in files)
{
    YourTextBox.Text += file + '\r\n';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM