
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Remove the first occurrence from the StringCollection in C#
To remove the first occurrence from the StringCollection, the code is as follows −
Example
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection stringCol = new StringCollection(); String[] arr = new String[] { "100", "200", "100", "400", "500" }; Console.WriteLine("Array elements..."); foreach (string res in arr) { Console.WriteLine(res); } stringCol.AddRange(arr); Console.WriteLine("Total number of elements = "+stringCol.Count); stringCol.Remove("100"); Console.WriteLine("Total number of elements now = "+stringCol.Count); } }
Output
This will produce the following output −
Array elements... 100 200 100 400 500 Total number of elements = 5 Total number of elements now = 4
Example
Let us see another example −
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection stringCol = new StringCollection(); String[] arr = new String[] { "10", "20", "30", "40", "50", "60", "70", "80" }; Console.WriteLine("Array elements..."); foreach (string res in arr) { Console.WriteLine(res); } stringCol.AddRange(arr); Console.WriteLine("Total number of elements = "+stringCol.Count); stringCol.Remove("50"); stringCol.Remove("60"); stringCol.Remove("70"); Console.WriteLine("Total number of elements now = "+stringCol.Count); } }
Output
This will produce the following output −
Array elements... 10 20 30 40 50 60 70 80 Total number of elements = 8 Total number of elements now = 5
- Related Articles
- Index of first occurrence in StringCollection in C#?
- Remove the first occurrence of a specific object from the ArrayList in C#
- Remove all the strings from the StringCollection in C#
- Remove from the specified index of the StringCollection in C#
- C# program to remove the first occurrence of a node in a Linked List
- Removing first occurrence of object from Collection in C#
- Removing first occurrence of specified value from LinkedList in C#
- First occurrence in the List that matches the specified conditions in C#
- Get the substring after the first occurrence of a separator in Java
- Get the index of the first occurrence of a separator in Java
- First occurrence of True number in Python
- Get the first occurrence of a substring within a string in Arduino
- JavaScript - Remove first n characters from string
- Golang Program To Remove The First Given Number Of Items From The Array
- Swift Program to remove the first given number of items from the array

Advertisements