- 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
Collections in C#
Collection classes are specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces.
The following are the collection classes in C# −
ArrayList
The ArrayList class represents ordered collection of an object that can be indexed individually.
Hashtable
Hashtable uses a key to access the elements in the collection.
SortedList
It uses a key as well as an index to access the items in a list.
BitArray
It represents an array of the binary representation using the values 1 and 0.
Stack
It represents a last-in, first out collection of object.
Queue
It represents a first-in, first out collection of object.
Let us see an example of the ArrayList class in C# −
Example
using System; using System. Collections; namespace Demo { class Program { static void Main(string[] args) { ArrayList al = new ArrayList(); al.Add(99); al.Add(76); al.Add(87); al.Add(46); al.Add(55); Console.WriteLine("Capacity: {0} ", al.Capacity); Console.WriteLine("Count: {0}", al.Count); Console.Write("Elements: "); foreach (int i in al) { Console.Write(i + " "); } Console.WriteLine(); Console.ReadKey(); } } }
Output
Capacity: 8 Count: 5 Elements: 99 76 87 46 55
Advertisements