如何在组合框中显示我的列表<string>或替代项?(C#)



实际上,我在c#中有一个学校的作品,我需要显示一个ComboBox列表,但我不喜欢显示代码:

combobox.Items.Add("example")
combobox.Items.Add("example2")
combobox.Items.Add("example3")

它很长,我试图用List或string[]进行优化,但我不知道如何制作。

你能帮我吗?

只需将ComboBox的ItemsSource属性设置为实现IEnumerable接口的任何属性:

combobox.ItemsSource = new string[] { "example1", "example2", "example3" };

有关详细信息,请参阅文档:ItemsControl.ItemsSource Property。

相关内容

最新更新