A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/c-sharp-get-a-collection-of-values-in-the-stringdictionary/ below:

C# | Get a collection of values in the StringDictionary

C# | Get a collection of values in the StringDictionary

Last Updated : 11 Jul, 2025

StringDictionary.Values

property is used to get a collection of values in the StringDictionary.

Syntax:
public virtual System.Collections.ICollection Values { get; }
Return Value:

An

ICollection

that provides the values in the StringDictionary.

Example 1: CSHARP
// C# code to get a collection
// of values in the StringDictionary
using System;
using System.Collections;
using System.Collections.Specialized;

class GFG {

    // Driver code
    public static void Main()
    {

        // Creating a StringDictionary named myDict
        StringDictionary myDict = new StringDictionary();

        // Adding key and value into the StringDictionary
        myDict.Add("A", "Apple");
        myDict.Add("B", "Banana");
        myDict.Add("C", "Cat");
        myDict.Add("D", "Dog");

        // Getting a collection of values
        // in the StringDictionary
        foreach(string val in myDict.Values)
        {
            Console.WriteLine(val);
        }
    }
}
Output:
Dog
Banana
Cat
Apple
Example 2: CSHARP
// C# code to get a collection
// of values in the StringDictionary
using System;
using System.Collections;
using System.Collections.Specialized;

class GFG {

    // Driver code
    public static void Main()
    {

        // Creating a StringDictionary named myDict
        StringDictionary myDict = new StringDictionary();

        // Adding key and value into the StringDictionary
        myDict.Add("3", "prime & odd");
        myDict.Add("2", "prime & even");
        myDict.Add("4", "non-prime & even");
        myDict.Add("9", "non-prime & odd");

        // Getting a collection of values
        // in the StringDictionary
        foreach(string val in myDict.Values)
        {
            Console.WriteLine(val);
        }
    }
}
Output:
prime & even
prime & odd
non-prime & odd
non-prime & even
Note: Reference:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4