将ListBox.SelectedObjectCollection转换为ListBox.ObjectCollection?

Chr*_*ell 2 c# collections casting listboxitems

是否可以将ListBox.SelectedObjectCollection转换为C#中的ListBox.ObjectCollection?如果是这样,我该怎么办呢?

jho*_*nna 9

我有一个接受的功能List<string>.

我可以通过强制转换SelectedItems和Items来传递它们.

试试这个:

SelectedItems.Cast<string>().ToList()
Items.Cast<string>().ToList()
Run Code Online (Sandbox Code Playgroud)

<string> 可以用其他一些对象类型替换.