Answers for "c# get dictionary key by value"

C#
0

get key in dictionary c#

public static void Main()
{
    Dictionary<string, string> dict = new Dictionary<string, string>()
    {
        {"1", "one"},
        {"2", "two"},
        {"3", "three"}
    };

    string key = KeyByValue(dict, "two");       
    Console.WriteLine("Key: " + key);
}
Posted by: Guest on November-05-2021
0

get key in dictionary c#

public static string GetKeyFromValue(string valueVar)
{
   foreach (string keyVar in dictionaryVar.Keys) 
   { 
      if (dictionaryVar[keyVar] == valueVar)
      {
         return keyVar;
      }
   }
   return null;
}
Posted by: Guest on November-05-2021
0

find the values of dictionaries in C sharp

//sets the dictionary item, "dictionary item" to 20
dictionary["dictionary item"] = 20;
Posted by: Guest on November-23-2020

Code answers related to "c# get dictionary key by value"

C# Answers by Framework

Browse Popular Code Answers by Language