如何获取组合框的内容并将它们添加到数组?

Cra*_*ith 3 c# arrays combobox

我已经看到了很多有关添加的内容ArrayComboBox,而不是周围的其他方式.我想把ComboBox它们的内容添加到一个Array被发送到另一个方法进行处理.

我已经.Items.Count确定了它的大小Array,但我无法弄清楚如何循环中的项目ComboBox.

Mag*_*nus 8

通过查看您对问题的评论,您可能想要这样:

var arr = ingredientComboBox.Items.Cast<Object>()
          .Select(item => item.ToString()).ToArray();
Run Code Online (Sandbox Code Playgroud)


yoh*_*nes 2

   string[] items = new string[currentComboBox.Items.Count];

   for(int i = 0; i < currentComboBox.Items.Count; i++)
   {
       items[i] = currentComboBox.Items[i].ToString();
   }
Run Code Online (Sandbox Code Playgroud)