Answers for "how to access item by key in dictionary c#"

C#
4

how to get element dictionary key in c# by index

dictionary[dictionary.ElementAt(index).Key]
Posted by: Guest on December-18-2020
6

access dic by key c#

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);
        }
    }
}
Posted by: Guest on June-20-2020

Code answers related to "how to access item by key in dictionary c#"

C# Answers by Framework

Browse Popular Code Answers by Language