如何获得CheckedListBox.checkedItems作为的StringList如何获得、CheckedListBox、StringList、checkedItems

2023-09-05 04:29:39 作者:幸福在哪里转弯i

我试图让 CheckedListBox.CheckedItems 作为一个StringList的。但我不知道如何得到它。我想使它作为一个使用LINQ单行。在.net-C#我的经验不足,不能够做到这一点。任何人都可以说该怎么办?

I am trying to get CheckedListBox.CheckedItems as a StringList. But I don't know how to get it. I am trying to make it as a one liner using LINQ. My insufficient experience in .Net-C# is not capable to do that. Can anybody say how to do that?

注:我使用的.Net-4.0

Note: I am using .Net-4.0.

推荐答案

如果您存储在这些项目中的值是字符串:

If the values you stored in those items are strings:

List<string> items = chk.CheckedItems.Cast<string>().ToList();

如果他们是一些自定义的类型,你可以使用该类型:

If they are of some custom type you could use that type:

List<SomeTypeUsedForTheItems> items = chk.CheckedItems.Cast<SomeTypeUsedForTheItems>().ToList();