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# | Add a string to the end of the StringCollection
Next article icon

How to create a StringCollection in C#

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

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.

Syntax:

public StringCollection ();

Example 1:




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

Example 2:




// C# Program to illustrate how
// to create a StringCollection
using System;
using System.Collections;
using System.Collections.Specialized;
  
class Geeks {
  
    // Main Method
    public static void Main(String[] args)
    {
  
        // sc is the StringCollection object
        // StringCollection() is the constructor
        // used to initializes a new
        // instance of the StringCollection class
        StringCollection sc = new StringCollection();
  
        Console.Write("Before Add Method: ");
  
        // Count property is used to get the
        // number of elements in StringCollection
        // It will give 0 as no elements
        // are present currently
        Console.WriteLine(sc.Count);
  
        Console.Write("After Add Method: ");
  
        // Adding elements in StringCollection
        sc.Add("A");
        sc.Add("B");
        sc.Add("C");
        sc.Add("D");
        sc.Add("E");
  
        // Count property is used to get the
        // number of elements in ld
        Console.WriteLine(sc.Count);
    }
}
 
 
Output:
  Before Add Method: 0  After Add Method: 5  

Reference:

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


Next Article
C# | Add a string to the end of the StringCollection

K

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

Similar Reads

  • 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 k
    2 min read
  • 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 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
  • 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
  • C# | Add a string to the end of the StringCollection
    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. StringCollection.Add(String) Method is used to add a string to the end of the StringCollection. Syn
    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# StringCollection Class
    In C#, the StringCollection class is part of the System.Collections.Specialized namespace. It provides a collection of strings that allows us to store and manage a list of strings easily. This class is a type-safe collection that automatically resizes as needed. StringCollection class accepts null a
    5 min read
  • How to Compare Strings in C#?
    A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s
    13 min read
  • How to get Synchronize access to the StringCollection in C#
    StringCollection.SyncRoot Property is used to get an object which can be used to synchronize access to the StringCollection. This class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. Syntax: public virtual object Sy
    2 min read
  • C# | How to create a SortedSet
    SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. Properties : In C#, SortedSet class can be used to store, remove or view elements. It maintains ascending order and does not store duplicate elements. It is suggeste
    2 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