【发布时间】:2018-01-24 22:42:00
【问题描述】:
我想使用 foreach 循环以另一种形式获取 List<string> 值
ReportTestForm.cs
private void ReportTestForm_Load(object sender, EventArgs e)
{
List<string> fieldList = new List<string>();
fieldList.Add("Name");
fieldList.Add("Class");
fieldList.Add("Address");
fieldList.Add("City");
ReportFilterForm report = new ReportFilterForm(fieldList);
report.Show(this);
}
ReportFilterForm.cs
public ReportFilterForm(List<string> fieldListFromReport)
{
List<string> record = new List<string>(fieldListFromReport);
foreach(string fields in record)
{
listBoxFieldNames.Items.Add(fields);
}
}
它抛出异常称为空引用异常
【问题讨论】:
标签: c# arrays winforms list collections