Get or set the value associated with specified key in ListDictionary in C#



To get or set the value associated with specified key in ListDictionary, the code is as follows −

Example

 Live Demo

using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       ListDictionary dict = new ListDictionary();       dict.Add("A", "Books");       dict.Add("B", "Electronics");       dict.Add("C", "Appliances");       dict.Add("D", "Pet Supplies");       dict.Add("E", "Clothing");       dict.Add("F", "Footwear");       Console.WriteLine("Value associated with key C = "+dict["C"]);    } }

Output

This will produce the following output −

Value associated with key C = Appliances

Example

Let us see another example −

 Live Demo

using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       ListDictionary dict = new ListDictionary();       dict.Add("A", "Books");       dict.Add("B", "Electronics");       dict.Add("C", "Appliances");       dict.Add("D", "Pet Supplies");       dict.Add("E", "Clothing");       dict.Add("F", "Footwear");       Console.WriteLine("Value associated with key C = "+dict["C"]);       dict["C"] = "HDD";       Console.WriteLine("Value associated with key C [Updated] = "+dict["C"]);    } }

Output

This will produce the following output −

Value associated with key C = Appliances Value associated with key C [Updated] = HDD
Updated on: 2019-12-05T10:42:04+05:30

132 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements