- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add a string to the end of the StringCollection in C#
To add a string to the end of the StringCollection, the code is as follows −
Example
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection strCol = new StringCollection(); strCol.Add("John"); strCol.Add("Tim"); strCol.Add("Gary"); strCol.Add("Katie"); strCol.Add("Andy"); strCol.Add("Amy"); strCol.Add("Scarlett"); strCol.Add("Jacob"); Console.WriteLine("Elements in StringCollection..."); foreach(Object ob in strCol) { Console.WriteLine(ob); } Console.WriteLine("Count of elements = "+strCol.Count); } }
Output
This will produce the following output −
Elements in StringCollection... John Tim Gary Katie Andy Amy Scarlett Jacob Count of elements = 8
Example
Let us see another example −
using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection strCol = new StringCollection(); strCol.Add("One"); strCol.Add("Two"); strCol.Add("Three"); strCol.Add("Four"); strCol.Add("Five"); Console.WriteLine("Elements in StringCollection..."); foreach(Object ob in strCol) { Console.WriteLine(ob); } } }
Output
This will produce the following output −
Elements in StringCollection... One Two Three Four Five
Advertisements