

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Index of first occurrence in StringCollection in C#?
- Remove all the strings from the StringCollection in C#
- Remove the first occurrence of a specific object from the ArrayList 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#
- First occurrence in the List that matches the specified conditions in C#
- Removing first occurrence of specified value from LinkedList 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
- Remove the first entry of the TreeMap in Java
- First occurrence of True number in Python
- Python Pandas - Indicate duplicate index values except for the first occurrence
- Get the first occurrence of a substring within a string in Arduino
- JavaScript - Remove first n characters from string
Advertisements