Wednesday, July 22, 2020

How to check if a set of key and value already exists in a dictionary

Dictionary<int, string> dict = new Dictionary<int, string>();
// initial value for demonstration
dict.Add(1, "Test");
dict.Add(2, "Test2");

use below method to check whether a key is exist or not

  if (!dict.ContainsKey(1))
        dict.Add(1, "Test");

 if (!dict.ContainsValue("Test"))
        dict.Add(1, "Test");

No comments:

Change default Port on Next.js app

 If any other app or process is running on port 3000 , you will get this error in your terminal Port 3000 is already in use. error Command f...