Si Thu
0
Q:

access dic by key c#

 Dictionary<string, string> dict = new Dictionary<string, string>();
 dict.Add("UserID", "test");
 string userIDFromDictionaryByKey = dict["UserID"];
5
var myKey = types.FirstOrDefault(x => x.Value == "one").Key;
1
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);
        }
    }
}
2
IDictionary<int, string> dict = new Dictionary<int, string>();
        
//or

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

New to Communities?

Join the community