Answers for "c# dictionary get value by key"

C#
10

c# dictionary get value by key

Dictionary<string, string> dict = new Dictionary<string, string>();
 dict.Add("UserID", "test");
 string userIDFromDictionaryByKey = dict["UserID"];
Posted by: Guest on April-23-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
1

get key value from object c#

Type myType = myObject.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());

foreach (PropertyInfo prop in props)
{
    object propValue = prop.GetValue(myObject, null);

    // Do something with propValue
}
Posted by: Guest on January-06-2021
12

c# dictionaries

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

Dictionary<int, string> dict = new Dictionary<int, string>();
Posted by: Guest on May-05-2020
2

c sharp add item to dictionary

// To add an item to a dictionary use 'Add()'
dict.Add(1,"One");
Posted by: Guest on February-26-2020

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

C# Answers by Framework

Browse Popular Code Answers by Language