Check out example codes for "c# dictionary get value by key". It will help you in understanding the concepts better.

Code Example 1

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

Code Example 2

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        Dictionary<string, int> dictionary = new Dictionary<string, int>();

        dictionary.Add("apple", 1);
        dictionary.Add("windows", 5);

        // See whether Dictionary contains this string.
        if (dictionary.ContainsKey("apple"))
        {
            int value = dictionary["apple"];
            Console.WriteLine(value);
        }

        // See whether it contains this string.
        if (!dictionary.ContainsKey("acorn"))
        {
            Console.WriteLine(false);
        }
    }
}

Code Example 3

IDictionary<int, string> dict = new Dictionary<int, string>();
        
//or

Dictionary<int, string> dict = new Dictionary<int, string>();

Code Example 4

<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array);   // $key = 1;
?>

Code Example 5

// To add an item to a dictionary use 'Add()'
dict.Add(1,"One");

Code Example 6

def method1(list,search_age):
	for name,age in list.iteritems():
		if age == search_age:
			return name
# Python 3
def method2(list,search_age):
	return [name for name,age in list.items() if age == search_age]

def method3(list,search_age):
	return list.keys()[list.values().index(search_age)]

Learn ReactJs, React Native from akashmittal.com