Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | Removing all entries from the StringDictionary
Next article icon

How to create a StringDictionary in C#

Last Updated : 27 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

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:




// C# Program to illustrate how
// to create a StringDictionary
using System;
using System.Collections;
using System.Collections.Specialized;
  
class Geeks {
  
    // Main Method
    public static void Main(String[] args)
    {
  
        // sd is the StringDictionary object
        // StringDictionary() is the constructor
        // used to initializes a new
        // instance of the StringDictionary class
        StringDictionary sd = new StringDictionary();
  
        // Count property is used to get the
        // number of elements in StringDictionary
        // It will give 0 as no elements
        // are present currently
        Console.WriteLine(sd.Count);
    }
}
 
 
Output:
  0  

Example 2:




// C# Program to illustrate how
// to create a StringDictionary
using System;
using System.Collections;
using System.Collections.Specialized;
  
class Geeks {
  
    // Main Method
    public static void Main(String[] args)
    {
  
        // sd is the StringDictionary object
        // StringDictionary() is the constructor
        // used to initializes a new
        // instance of the StringDictionary class
        StringDictionary sd = new StringDictionary();
  
        Console.Write("Before Add Method: ");
  
        // Count property is used to get the
        // number of elements in StringDictionary
        // It will give 0 as no elements
        // are present currently
        Console.WriteLine(sd.Count);
  
        // Adding key/value pairs in sd
        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: ");
  
        // Count property is used to get the
        // number of elements in sd
        Console.WriteLine(sd.Count);
    }
}
 
 
Output:
  Before Add Method: 0  After Add Method: 6  

Reference:

  • https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringdictionary.-ctor?view=netframework-4.7.2


Next Article
C# | Removing all entries from the StringDictionary

K

Kirti_Mangal
Improve
Article Tags :
  • C#
  • CSharp-Specialized-Namespace
  • CSharp-Specialized-StringDictionary

Similar Reads

  • How to create a ListDictionary in C#
    ListDictionary() constructor is used to initialize a new empty instance of the ListDictionary class using the default comparer. ListDictionary is a specialized collection. It comes under the System.Collections.Specialized namespace. This type represents a non-generic dictionary type. It is implement
    2 min read
  • How to create a StringCollection in C#
    StringCollection() constructor is used to initializing a new instance of the StringCollection class. StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace
    2 min read
  • How to create an OrderedDictionary in C#
    OrderedDictionary() constructor is used to initialize a new instance of the OrderedDictionary class which will be empty and will have the default initial capacity. OrderedDictionary Class represents a collection of key/value pairs that are accessible by the key or index. It is present in System.Coll
    2 min read
  • How to create the StringBuilder in C#
    StringBuilder() constructor is used to initialize a new instance of the StringBuilder class which will be empty and will have the default initial capacity. StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutabl
    2 min read
  • C# | Removing all entries from the StringDictionary
    StringDictionary.Clear method is used to remove all the entries from the StringDictionary. Syntax: public virtual void Clear (); Exception: This method will give the NotSupportedException if the StringDictionary is read-only. Example: // C# code to remove all entries // from the StringDictionary usi
    2 min read
  • C# | How to create a SortedList
    SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. Properties of SortedList: Internally the object of SortedList maintains two arr
    2 min read
  • C# | How to create a Stack
    Stack() constructor is used to initialize a new instance of the Stack class which will be empty and will have the default initial capacity. Stack represents a last-in, first out collection of object. It is used when you need last-in, first-out access to items. When you add an item in the list, it is
    2 min read
  • C# StringDictionary Class
    In C#, the StringDictionary class is the part of the System.Collections.Specialized namespace. It is a collection of key-value pairs where the keys are strings and values are objects. It is similar to a Hashtable. But it is specifically designed for use with string keys. Keys are always strings, and
    5 min read
  • C# | Get a collection of keys in the StringDictionary
    StringDictionary.Keys property is used to get a collection of keys in the StringDictionary. Syntax: public virtual System.Collections.ICollection Keys { get; } Return Value: An ICollection that provides the keys in the StringDictionary. Below given are some examples to understand the implementation
    2 min read
  • How to get Synchronize access to the StringDictionary in C#
    StringDictionary.SyncRoot Property is used to get an object which can be used to synchronize access to the StringDictionary. 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 t
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences