C# | Get a collection of values in the StringDictionary
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:
// 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); } } } |
chevron_right
filter_none
Output:
Dog Banana Cat Apple
Example 2:
// 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); } } } |
chevron_right
filter_none
Output:
prime & even prime & odd non-prime & odd non-prime & even
Note:
- The order of the values in the ICollection is unspecified, but it is the same order as the associated keys in the ICollection returned by the Keys method.
- The returned ICollection is not a static copy. Instead, the ICollection refers back to the values in the original StringDictionary. Therefore, changes to the StringDictionary continue to be reflected in the ICollection.
- Retrieving the value of this property is an O(1) operation.
Reference:
Recommended Posts:
- C# | Get a collection of keys in the StringDictionary
- C# | Add key and value into StringDictionary
- C# | Get or set the value associated with the specified key in StringDictionary
- How to create a StringDictionary in C#
- C# | Gets or sets the value at the specified key in StringDictionary
- C# | StringDictionary Class
- C# | Removing all entries from the StringDictionary
- C# | Remove entry with specified key from the StringDictionary
- How to get Synchronize access to the StringDictionary in C#
- C# | Get the number of key/value pairs in the StringDictionary
- C# | Check if the StringDictionary contains a specific key
- C# | Get an enumerator that iterates through the stringDictionary
- C# | Check if the StringDictionary contains a specific value
- C# | Copy StringDictionary to Array at the specified index
- C# | Check if two StringDictionary objects are equal or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



