Dictionary initialize in C#
You can easily initialize a Dictionary Object using a Collection Initialize, which is there since C# 3.0.
Collection initialize adds one of the parameter as Key and another as Value corresponding to the assigned Key.
You can easily initialize a Dictionary Object using a Collection Initialize, which is there since C# 3.0.
Collection initialize adds one of the parameter as Key and another as Value corresponding to the assigned Key.
Dictionary<int, string> students = new Dictionary<int, string> {
{1, "Student 1" },
{2, "Student 2" },
{3, "Student 3" },
{4, "Student 4" }
};
{1, "Student 1" },
{2, "Student 2" },
{3, "Student 3" },
{4, "Student 4" }
};