Open In App

C# | Get an ICollection containing the values in ListDictionary

ListDictionary.Values property is used to get an ICollection containing the values in the ListDictionary.

Syntax:



public System.Collections.ICollection Values { get; }

Return Value : It returns an ICollection containing the values in the ListDictionary.

Below are the programs to illustrate the use of ListDictionary.Values property:



Example 1:




// C# code to get an ICollection
// containing the values in the ListDictionary
using System;
using System.Collections;
using System.Collections.Specialized;
  
class GFG {
  
    // Driver code
    public static void Main()
    {
  
        // Creating a ListDictionary named myDict
        ListDictionary myDict = new ListDictionary();
  
        myDict.Add("Australia", "Canberra");
        myDict.Add("Belgium", "Brussels");
        myDict.Add("Netherlands", "Amsterdam");
        myDict.Add("China", "Beijing");
        myDict.Add("Russia", "Moscow");
        myDict.Add("India", "New Delhi");
  
        // Get an ICollection containing
        // the values in the ListDictionary
        ICollection ic = myDict.Values;
  
        // Displaying the values in ICollection ic
        foreach(String str in ic)
        {
            Console.WriteLine(str);
        }
    }
}

Output:
Canberra
Brussels
Amsterdam
Beijing
Moscow
New Delhi

Example 2 :




// C# code to get an ICollection
// containing the values in the ListDictionary
using System;
using System.Collections;
using System.Collections.Specialized;
  
class GFG {
  
    // Driver code
    public static void Main()
    {
  
        // Creating a ListDictionary named myDict
        ListDictionary myDict = new ListDictionary();
  
        myDict.Add("I", "first");
        myDict.Add("II", "second");
        myDict.Add("III", "third");
        myDict.Add("IV", "fourth");
        myDict.Add("V", "fifth");
  
        // Get an ICollection containing
        // the values in the ListDictionary
        ICollection ic = myDict.Values;
  
        // Displaying the values in ICollection ic
        foreach(String str in ic)
        {
            Console.WriteLine(str);
        }
    }
}

Output:
first
second
third
fourth
fifth

Note:

Reference:


Article Tags :
C#