struct process
{
public int Proc_Id;
public int Proc_BurstTime;
public int Proc_Priority;
};
readonly process[] ProcessList = new process[]
{
new process{ Proc_Id = 1, Proc_BurstTime = 3000, Proc_Priority = 1},
new process{ Proc_Id = 2, Proc_BurstTime = 5000, Proc_Priority = 2},
new process{ Proc_Id = 3, Proc_BurstTime = 1000, Proc_Priority = 3},
new process{ Proc_Id = 4, Proc_BurstTime = 10000, Proc_Priority = 4}
};
private void Form1_Load(object sender, EventArgs e)
{
initial_ProcessList.Items.AddRange(ProcessList);
}
这是我得到的错误:
The best overloaded method match for 'System.Windows.Forms.ListBox.ObjectCollection.AddRange(System.Windows.Forms.ListBox.ObjectCollection)' has some invalid arguments
Argument 1: cannot convert from 'OS450_Proj1.Form1.process[]' to 'System.Windows.Forms.ListBox.ObjectCollection'
我知道它看起来不喜欢那种数组,但是有什么办法可以填充列表框吗?如果也是因为没有字符串或任何东西可以“打印”到列表中,我是否需要将字符串值添加到结构中并为数组(ProcessList)中的所有值初始化它?如果是这样,添加到列表框时我该怎么做?