
- 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
Get or set the number of elements that the ArrayList can contain in C#
To get or set the number of elements that the ArrayList can contain, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add(25); arrList.Add(50); arrList.Add(75); arrList.Add(100); arrList.Add(125); arrList.Add(150); arrList.Add(175); arrList.Add(200); arrList.Add(225); arrList.Add(250); Console.WriteLine("Elements in ArrayList..."); foreach(int i in arrList) { Console.WriteLine(i); } Console.WriteLine("Count of elements = " + arrList.Count); Console.WriteLine("Capacity =" + arrList.Capacity); } }
Output
This will produce the following output −
Elements in ArrayList... 25 50 75 100 125 150 175 200 225 250 Count of elements = 10 Capacity =16
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main() { ArrayList arrList = new ArrayList(10); arrList.Add(25); arrList.Add(50); arrList.Add(75); arrList.Add(100); Console.WriteLine("Elements in ArrayList..."); foreach(int i in arrList) { Console.WriteLine(i); } Console.WriteLine("Count of elements = " + arrList.Count); Console.WriteLine("Capacity =" + arrList.Capacity); } }
Output
This will produce the following output −
Elements in ArrayList... 25 50 75 100 Count of elements = 4 Capacity =10
- Related Questions & Answers
- Get or set the number of elements in the BitArray in C#
- Get the number of elements actually contained in the ArrayList in C#
- Maximum number of segments that can contain the given points in C++
- Set the capacity to the actual number of elements in the ArrayList in C#?
- Get or set the element at the specified index in ArrayList in C#
- Get the number of elements in the SortedSet in C#
- Reverse the order of the elements in the entire ArrayList or in the specified range in C#
- Get the number of elements contained in the Queue in C#
- Get the number of elements contained in the Stack in C#
- Adding elements to the end of the ArrayList in C#
- Get the number of elements contained in Collection in C#
- Get the number of elements contained in SortedList in C#
- Remove a range of elements from the ArrayList in C#
- Find the Number which contain the digit d in C++
- Maximum difference elements that can added to a set in C++
Advertisements