[英]How I can read the items of a collection from a text file
I have a checkedListBox
and in collection items I want to add what I have in a text file installer.ini
after #product=name of checkbox
. 我有一个
checkedListBox
,在集合项中,我想在checkedListBox
#product=name of checkbox
之后添加文本文件installer.ini
中的内容。 How I can do this ? 我该怎么做? Something like this :
像这样的东西:
var lines = System.IO.File.ReadAllLines(path + "installer.ini");
var items = new List<string>();
lines.Where(x => x.StartsWith("#product="))
.Select(x =>x.Replace("#product=", "").Trim())
.ToList()
.ForEach(item =>
{
string line;
items.Add(line);
}
);
checkedListBox2.AddRange( items );
}
You almost did everything right: 您几乎正确地完成了所有操作:
var items = System.IO.File.
ReadAllLines(path + "installer.ini").
Where(x => x.StartsWith("#product=")).
Select(x =>x.Replace("#product=", "").Trim()).
ToArray();
ListBox2.Items.AddRange(items);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.