Most succinct way to convert ListBox.items to a generic list

后端 未结 5 1525
日久生厌
日久生厌 2021-01-30 12:20

I am using C# and targeting the .NET Framework 3.5. I\'m looking for a small, succinct and efficient piece of code to copy all of the items in a ListBox to a List

5条回答
  •  温柔的废话
    2021-01-30 13:18

    What about:

    myOtherList.AddRange(lbMyListBox.Items);
    

    EDIT based on comments and DavidGouge's answer:

    myOtherList.AddRange(lbMyListBox.Items.Select(item => ((ListItem)item).Value));
    

提交回复
热议问题