问题
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