C# | Gets an ICollection containing the values in the Hashtable
Last Updated :
01 Feb, 2019
Hashtable.Values Property is used to get an ICollection containing the values in the Hashtable.
Syntax:
public virtual System.Collections.ICollection Values { get; }
Return Value: This property returns an ICollection containing the values in the Hashtable.
Note:
- The order of values in the ICollection is unspecified.
- Retrieving the value of this property is an O(1) operation.
Below programs illustrate the use of above-discussed property:
Example 1:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Hashtable myTable = new Hashtable();
myTable.Add( "g" , "geeks" );
myTable.Add( "c" , "c++" );
myTable.Add( "d" , "data structures" );
myTable.Add( "q" , "quiz" );
ICollection c = myTable.Values;
foreach ( string str in c)
Console.WriteLine(str + myTable[str]);
}
}
|
Output:
data structures
c++
quiz
geeks
Example 2:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Hashtable myTable = new Hashtable();
myTable.Add( "India" , "Country" );
myTable.Add( "Chandigarh" , "City" );
myTable.Add( "Mars" , "Planet" );
myTable.Add( "China" , "Country" );
ICollection c = myTable.Values;
foreach ( string str in c)
Console.WriteLine(str + myTable[str]);
}
}
|
Output:
City
Country
Country
Planet
Reference:
Share your thoughts in the comments
Please Login to comment...