因此,我试图通过调用另一个将返回n is not None
的类中的方法来从ComboBox
填充List
。
List
答案 0 :(得分:0)
嗯,List<T>
没有GetCC()
,但是Line
有;像这样的东西:
private void startingStation_SelectedIndexChanged(object sender, EventArgs e) {
//TODO: you have to obtain Line instance here
Line line = new Line();
// In order to avoid constant redrawing: we want repaint combobox once,
// after all items being inserted
startingStation.BeginUpdate();
try {
// It is line (not List<T>) that provides GetCC() method
foreach (Station station in line.GetCC()) {
// String interpolation - $"..." is more readable than concatenation
startingStation.Items.Add($"{station.Number} {station.Desc}");
}
}
finally {
startingStation.EndUpdate();
}
}
编辑:您可以借助 Linq (专门为查询 设计的)改善GetCC()
的实现:
using System.Linq;
...
class Line : Station {
...
public List<Station> GetCC() {
return file
.Where(item => item.Number.Contains("CC"))
.ToList();
}
...
}