Challenge for an unknown WinForm element



  • public void FunctionA(Object element)
    {
     element.Items.Clear();
    }
    

    Example of use:

    FunctionA(checkedListBox1);
    

    Function FunctionA There will be arguments only checkedListBox and comboBoxboth elements have a method .Items.Clear();

    How do you make it work?



  • public void FunctionA(IList aList)
    {
      aList.Clear();
    }
    
    FunctionA(checkedListBox1.Items);
    FunctionA(comboBox1.Items);
    

    Update

    What do you do if you add checkedListBox1 you need to do?

    I default chekedbox.

    No miracles.

    if (aList is CheckedListBox.ObjectCollection)
    {
    ((CheckedListBox.ObjectCollection)aList).Add(Text, true);
    }
    else
    {
    aList.Add(Text);
    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2