Answers for "c# initialize dictionary"

C#
18

c# initialize dictionary

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

c# inline initialize dictionary

var testDict = new Dictionary<string, string>() { ["key1"] = "value1", ["key2"] = "value2" };
Posted by: Guest on February-18-2020
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

C# Answers by Framework

Browse Popular Code Answers by Language