CheckedListBox.CheckedItemCollection.cs 856 B

123456789101112131415161718192021222324252627
  1. using System.Collections;
  2. namespace System.Windows.Forms
  3. {
  4. public partial class CheckedListBox
  5. {
  6. public class CheckedItemCollection : CollectionBase
  7. {
  8. private static string message = "Collection is read only.";
  9. public object this[int index] => ((Item)List[index]).Value;
  10. internal void Add(object obj) => List.Add(obj);
  11. public new void Clear() => throw new NotSupportedException(message);
  12. public new void RemoveAt(int index) => throw new NotSupportedException(message);
  13. // the reason for this method is that enumerator must return Item.Value rather than Item itself
  14. public new IEnumerator GetEnumerator()
  15. {
  16. foreach (Item item in List)
  17. yield return item.Value;
  18. }
  19. }
  20. }
  21. }