Answers for "c# dictionary"

18

c# initialize dictionary

Dictionary<int, string> dictNew = new Dictionary<int,string>()
{
  {1, "true"},
  {2, "false"}
}
Posted by: Guest on May-07-2020
5

dictionary c#

// Create a dictionary with 2 string values
Dictionary<string, string> capitalOf = new Dictionary<string, string>();

// Add items to the dictionary
capitalOf.Add("Japan", "Tokio");
capitalOf.Add("Portugal", "Lissabon");

// Loop over the dictionary and output the results to the console
foreach (KeyValuePair<string, string> combi in capitalOf)
{
  Console.WriteLine("The capital of " + combi.Key + " is " + combi.Value);
}
Posted by: Guest on October-30-2021
2

c sharp create dictionary

// To initialize a dictionary, see below:
IDictionary<int, string> dict = new Dictionary<int, string>();
// Make sure to give it the right type of key and value

// To add values use 'Add()'
dict.Add(1,"One");
dict.Add(2,"Two");
dict.Add(3,"Three");

// You can also do this together with the creation
IDictionary<int, string> dict = new Dictionary<int, string>()
{
	{1,"One"},
	{2, "Two"},
	{3,"Three"}
};
Posted by: Guest on February-26-2020
7

java dictionary

Map<String, String> dictionary = new HashMap<String, String>();

dictionary.put("key", "value");
String value = dictionary.get("key");
Posted by: Guest on May-09-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
4

declare dictionary c#

var students2 = new Dictionary<int, StudentName>()
        {
            [111] = new StudentName { FirstName="Sachin", LastName="Karnik", ID=211 },
            [112] = new StudentName { FirstName="Dina", LastName="Salimzianova", ID=317 } ,
            [113] = new StudentName { FirstName="Andy", LastName="Ruth", ID=198 }
        };
Posted by: Guest on January-26-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language