C# Dictionary class is a generic collection of a (key, value) pair. Dictionary<TKey,TValue> class and its methods can be used to add, update, find and remove elements from the collection. Dictionary.Remove() and Dictionary.Clear() methods are used to remove elements of the collection. The Remove method removes elements matching with the key passed in the Remove method. The Clear method removes all elements from the dictionary.
- Dictionary<string, Int16> AuthorList = new Dictionary<string, Int16>();
- AuthorList.Add("Mahesh Chand", 35);
- AuthorList.Add("Mike Gold", 25);
- AuthorList.Add("Praveen Kumar", 29);
- AuthorList.Add("Raj Beniwal", 21);
- AuthorList.Add("Dinesh Beniwal", 84);
- // Remove item with key = 'Mahesh Chand'
- AuthorList.Remove("Mahesh Chand");
- // Remove all items
- AuthorList.Clear();

jay DeePosted Nov 29, 2012, 8:47 AM EST
I have a checkboxlist bound to a dictionary. How would I be able to delete only the selected items in my checkbox list? I tried this: foreach(lisitems li in checkboxList1.Items) { if(li.selected == true) { mydictionary.Remove(CheckBoxList1.SelectedItem.ToString()); } } //Bind CheckBox to Dictionary but only the first item get deleted