
- 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
What are dynamic arrays in C#?
Dynamic arrays are growable arrays and have an advantage over static arrays. This is because the size of an array is fixed.
To create arrays dynamically in C#, use the ArrayList collection. It represents an ordered collection of an object that can be indexed individually. It also allows dynamic memory allocation, adding, searching and sorting items in the list.
The following is an example showing how to create arrays dynamically in C# −
Example
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { ArrayList al = new ArrayList(); al.Add(577); al.Add(286); Console.WriteLine("Count: {0}", al.Count); Console.Write("List: "); foreach (int i in al) { Console.Write(i + " "); } Console.WriteLine(); Console.ReadKey(); } } }
Output
Count: 2 List: 577 286
- Related Articles
- What are variable length (Dynamic) Arrays in Java?
- What are dynamic data types in C#?
- What are Dynamic routing algorithms in computer networks?
- What are the Dynamic Password Authentication in information security?
- What are mixed arrays in C#?
- What are jagged arrays in C#?
- What are associative Arrays in JavaScript?
- What are the types of Dynamic Branch Prediction?
- What are flooding, static routing and dynamic routing?
- How to Perform Numpy Broadcasting using Python using dynamic arrays?
- What are parameter/param arrays in C#?
- What are two-dimensional arrays in C#?
- What are differences between static binding and dynamic binding in Java?
- What are the types of arrays in Java?
- What is dynamic binding in Java?

Advertisements