How to create a StringDictionary in C#
StringDictionary() constructor is used to initialize a new instance of the StringDictionary class which will be empty and will have the default initial capacity. StringDictionary is a specialized collection. This class comes under the System.Collections.Specialized
namespace. It only allows string keys and string values. It suffers from performance problems. It implements a hash table with the key and the value strongly typed to be strings rather than objects.
Syntax:
public StringDictionary ();
Example 1:
using System;
using System.Collections;
using System.Collections.Specialized;
class Geeks {
public static void Main(String[] args)
{
StringDictionary sd = new StringDictionary();
Console.WriteLine(sd.Count);
}
}
|
Example 2:
using System;
using System.Collections;
using System.Collections.Specialized;
class Geeks {
public static void Main(String[] args)
{
StringDictionary sd = new StringDictionary();
Console.Write( "Before Add Method: " );
Console.WriteLine(sd.Count);
sd.Add( "1" , "C" );
sd.Add( "2" , "C++" );
sd.Add( "3" , "Java" );
sd.Add( "4" , "Python" );
sd.Add( "5" , "C#" );
sd.Add( "6" , "HTML" );
Console.Write( "After Add Method: " );
Console.WriteLine(sd.Count);
}
}
|
Output:
Before Add Method: 0
After Add Method: 6
Reference:
Last Updated :
27 Feb, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...