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

Example of use:

 FunctionA(checkedListBox1); 

The FunctionA function will be supplied with arguments only checkedListBox and comboBox , both elements have a method .Items.Clear() ;

How to make it work?

    2 answers 2

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

    Update

    What to do if in case of adding checkedListBox1, the default checkbox is in the cheked position.

    Well, no miracles.

     if (aList is CheckedListBox.ObjectCollection) { ((CheckedListBox.ObjectCollection)aList).Add(Text, true); } else { aList.Add(Text); } 
    • Error 3 The use of the generic type "System.Collections.Generic.IList <T>" requires arguments of type "1". Swears at "IList aList" - LorDo
    • @LorDo add using System.Collections; to the beginning of the file - Igor
    • there is still a nuance. What to do if in case of adding checkedListBox1, the default checkbox is in the cheked position. (If you use the same system for the code aList.Add (Text); - LorDo

    Well, something like this:

     if (element.GetType() == typeof(CheckedListBox)) ((CheckedListBox)element).Items.Clear(); else if (element.GetType() == typeof(ComboBox)) ((CheckedListBox)element).Items.Clear();