Get an ICollection containing the values in ListDictionary in C#


To get an ICollection containing the values 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 listDict = new ListDictionary();
      listDict.Add("1", "Laptop");
      listDict.Add("2", "Tablet");
      listDict.Add("3", "Desktop");
      listDict.Add("4", "Speaker");
      listDict.Add("5", "Earphone");
      listDict.Add("6", "Headphone");
      ICollection col = listDict.Values;
      foreach(String s in col){
         Console.WriteLine(s);
      }
   }
}

Output

This will produce the following output −

Laptop
Tablet
Desktop
Speaker
Earphone
Headphone

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 listDict = new ListDictionary();
      listDict.Add("A", "Tom");
      listDict.Add("B", "John");
      listDict.Add("C", "Kevin");
      listDict.Add("D", "Tim");
      ICollection col = listDict.Values;
      foreach(String s in col){
         Console.WriteLine(s);
      }
   }
}

Output

This will produce the following output −

Tom
John
Kevin
Tim

Updated on: 05-Dec-2019

80 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements