Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Get key by his value on Dict C#

var myKey = myDict.FirstOrDefault(x => x.Value == "myValue").Key;
// return the first key finded in the dict associated to this value
Comment

c# dictionary get value by key

 Dictionary<string, string> dict = new Dictionary<string, string>();
 dict.Add("UserID", "test");
 string userIDFromDictionaryByKey = dict["UserID"];
Comment

c# dictionary get key by value

            Dictionary<string, string> dict = new Dictionary<string, string>()
              {
                {"1", "one"},
                {"2", "two"},
                {"3", "three"}
              };
            foreach (var item in dict)
            {
                if(item.Value == "One")
                {
                    var firstElementKey = item.Key;
                  	Console.WriteLine(firstElementKey);
                }
            }
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: can you have multiple statement in a case c# 
Csharp :: foreach enum 
Csharp :: how to move object with keyboard in unity 3D 
Csharp :: get out of foreach statement c# 
Csharp :: Unity Children Destroy 
Csharp :: npm install --save vue-route@n 
Csharp :: unity get parent object 
Csharp :: array to list c 
Csharp :: add variable to the beginning of a list c# 
Csharp :: Configure Automapper 
Csharp :: textbox in xamarin forms 
Csharp :: play animation through script unity 
Csharp :: c# cancellationtoken example 
Csharp :: rock paper scissors c# 
Csharp :: validating file upload asp.net core mvc 
Csharp :: how to rotate object in unity only on one axis 
Csharp :: fluent assertion exception 
Csharp :: c# see if list contains any duplicates 
Csharp :: c# datagridview header color 
Csharp :: new ienumerable 
Csharp :: declare dictionary c# 
Csharp :: c# set cursor pos 
Csharp :: c# remove char from string 
Csharp :: c# return 2 values 
Csharp :: rotation unity script 2d 
Csharp :: c# kill one excel process 
Csharp :: join array in c# 
Csharp :: click in vue 
Csharp :: check if palindrome recursion in c# 
Csharp :: c# create excel file 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =