How to get CheckedListBox.checkedItems as a stringlist

巧了我就是萌 提交于 2019-12-23 12:55:19

问题


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?

Note: I am using .Net-4.0.


回答1:


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();


来源:https://stackoverflow.com/questions/11966614/how-to-get-checkedlistbox-checkeditems-as-a-stringlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!