C# | Add a string to the end of the StringCollection Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: public int Add (string value); Here, value is the string to add to the end of the StringCollection. The value can be null. Return Value: The zero-based index at which the new element is inserted. Note: If Count is less than the capacity, this method is an O(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count. Below programs illustrate the use of StringCollection.Add(String) Method: Example 1: CSHARP // C# code to add a string to the // end of the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // Adding elements in StringCollection myCol.Add("A"); myCol.Add("B"); myCol.Add("C"); myCol.Add("D"); myCol.Add("E"); // Displaying objects in myCol foreach(Object obj in myCol) { Console.WriteLine(obj); } } } Output: A B C D E Example 2: CSHARP // C# code to add a string to the // end of the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // Adding elements in StringCollection myCol.Add("2"); myCol.Add("4"); myCol.Add("6"); myCol.Add("8"); myCol.Add("10"); // Displaying objects in myCol foreach(Object obj in myCol) { Console.WriteLine(obj); } } } Output: 2 4 6 8 10 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.add?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, ... S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Specialized-Namespace CSharp-Specialized-StringCollection +1 More Similar Reads Interview Preparation Interview Preparation For Software Developers Must Coding Questions - Company-wise Must Do Coding Questions - Topic-wise Company-wise Practice Problems Company Preparation Competitive Programming Software Design-Patterns Company-wise Interview Experience Experienced - Interview Experiences Internship - Interview Experiences Practice @Geeksforgeeks Problem of the Day Topic-wise Practice Difficulty Level - School Difficulty Level - Basic Difficulty Level - Easy Difficulty Level - Medium Difficulty Level - Hard Leaderboard !! Explore More... Data Structures Arrays Linked List Stack Queue Binary Tree Binary Search Tree Heap Hashing Graph Advance Data Structures Matrix String All Data Structures Algorithms Analysis of Algorithms Searching Algorithms Sorting Algorithms Pattern Searching Geometric Algorithms Mathematical Algorithms Randomized Algorithms Greedy Algorithms Dynamic Programming Divide & Conquer Backtracking Branch & Bound All Algorithms Programming Languages C C++ Java Python C# Go Lang SQL PHP Scala Perl Kotlin Web Technologies HTML CSS JavaScript Bootstrap Tailwind CSS AngularJS ReactJS jQuery NodeJS PHP Web Design Web Browser File Formats Computer Science Subjects Operating Systems DBMS Computer Network Computer Organization & Architecture TOC Compiler Design Digital Elec. & Logic Design Software Engineering Engineering Mathematics Data Science & ML Complete Data Science Course Data Science Tutorial Machine Learning Tutorial Deep Learning Tutorial NLP Tutorial Machine Learning Projects Data Analysis Tutorial Tutorial Library Python Tutorial Django Tutorial Pandas Tutorial Kivy Tutorial Tkinter Tutorial OpenCV Tutorial Selenium Tutorial GATE CS GATE CS Notes Gate Corner Previous Year GATE Papers Last Minute Notes (LMNs) Important Topic For GATE CS GATE Course Previous Year Paper: CS exams Like