
- 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
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
- Related Articles
- Thread-Safe collections in C#
- What are generic collections in C#?
- How to handle empty collections in C#
- Make your collections thread-safe in C#
- Difference between Traditional Collections and Concurrent Collections in java
- Collections in Python
- What are key-based I/O collections in C#?
- C# Program to Merge Two Hashtable Collections
- Collections in Java\n
- Multidimensional Collections in Java
- Indexed collections in JavaScript
- Keyed collections in JavaScript
- How to use Remove, RemoveAt, RemoveRange methods in C# list collections?
- How to Monitor Collections in Postman?
- Need of Concurrent Collections in Java

Advertisements