How to remove item from a dictionary in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
   
class Program
{
    static void Main() {
        Dictionary<string, int> dic = new Dictionary<string, int>();  
           
        dic.Add("c#", 1);
        dic.Add("c", 2);
        dic.Add("c++", 3);
        dic.Add("java", 4);
        dic.Add("php", 5);

        dic.Remove("java");
         
        foreach(KeyValuePair<string, int> item in dic) { 
              Console.WriteLine("{0} : {1}", item.Key, item.Value); 
        }
    }
}
   
   
   
/*
run:
   
c# : 1
c : 2
c++ : 3
php : 5
 
*/

 



answered Sep 12, 2019 by avibootz

Related questions

2 answers 217 views
1 answer 118 views
118 views asked Feb 28, 2023 by avibootz
1 answer 202 views
202 views asked Jan 7, 2017 by avibootz
1 answer 146 views
1 answer 185 views
185 views asked Jan 12, 2021 by avibootz
1 answer 193 views
...