- Trending Categories
- 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
How to use ArrayList class in C#?
ArrayList class represents an ordered collection of an object that can be indexed individually. It is an alternative to an array.
The following table lists some of the commonly used properties of the ArrayList class −
Sr.No. | Property & Description |
---|---|
1 | Capacity Gets or sets the number of elements that the ArrayList can contain. |
2 | Count Gets the number of elements actually contained in the ArrayList. |
3 | IsFixedSize Gets a value indicating whether the ArrayList has a fixed size. |
4 | IsReadOnly Gets a value indicating whether the ArrayList is read-only. |
5 | Item Gets or sets the element at the specified index. |
The following is an example showing how to work with ArrayList in C# and finding the capacity. The default capacity is 4 −
Example
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { ArrayList x = new ArrayList(); x.Add(977); x.Add(568); x.Add(345); x.Add(765); Console.WriteLine("Capacity: {0} ", x.Capacity); } } }
Output
Capacity: 4
Advertisements