如何将ListBox.items转换为c#中的数组集合字符串

use*_*120 5 c# casting listbox

我已将数组绑定为ListBox的数据源.现在我需要将listbox.Items转换为数组集合的字符串.

foreach (string s1 in listBoxPart.Items)
{
   clist.Add(s1);
}
Run Code Online (Sandbox Code Playgroud)

这里clist是字符串列表,那么如何将ListBox.items添加到clist?

Yuv*_*kov 15

您可以使用string内部任何包含内容.这意味着将选择其中实际为a的任何元素:ItemsOfTypeObjectCollectionstring

string[] clist = listBoxPart.Items.OfType<string>().ToArray();
Run Code Online (Sandbox Code Playgroud)