How to update the value in a Dictionary in C# ?

Below is a sample code snippet demonstrating how to update the value that is stored within the dictionary using C#. We access the dictionary with the key as index and set the value.

How to update the value in a Dictionary in C# ?

using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, string> dataDictionary = new Dictionary<string, string>();
            dataDictionary["key1"] = "Value 1";
            dataDictionary["key1"] = "Value 2";
            Console.WriteLine(dataDictionary["key1"]);
            Console.ReadLine();
        }
    }
}