我一派,并处罚金此链接,但仍然没有工作 Convert List<T> to object[]如何将genericlist转换为一个对象数组 - > [对象]
我想转换为int的列表,以对象数组。为什么?因为我想在Combbox中添加列表作为对象数组,它就是参数。
问题是它在Combobox中仅添加“一个项目”Object []数组,而“tempList”包含4个int类型的项目。
我喜欢在对象[](对象数组)中添加4个项目,现在它添加为1项目,并在调试器中显示Object []数组。
当我看在调试器和类型:
客户 - 它显示对象[1],并且当I型
客户[0]它显示对象[4],因此实际上被添加4项,但我怎样才能得到这些值。
List<int> tempList= new CustomersRepository().GetAll().Select(a => a.Numero).ToList();
object[] customers = new object[] { tempList.Cast<object>().ToArray() };
ComboBox.Items.AddRange(customers);
你在哪里可以在'comboBox'上找到'AddRange'方法?我认为你的意思是'Items.AddRange' –
是的,的确输入错误。它的combobox.items.addrange(xx),刚刚更正。 – ethem