
- 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
Is it possible to resize an array in C#
You cannot resize an array in C#, but using Array.Resize you can replace the array with a new array of different size.
The following is our array −
char[] ch = new char[10]; ch[0] = 'a'; ch[1] = 'b';
Now, resize −
Array.Resize<char>(ref ch, 10);
The following is the complete example −
Example
using System; class Program { static void Main() { char[] ch = new char[10]; ch[0] = 'a'; ch[1] = 'b'; // Resize array Array.Resize<char>(ref ch, 10); // Set value for new elements ch[2] = 'c'; ch[3] = 'd'; ch[4] = 'e'; ch[5] = 'f'; ch[6] = 'g'; ch[7] = 'h'; ch[8] = 'i'; ch[9] = 'j'; Console.WriteLine("New Array: "+ new string(ch)); } }
Output
New Array: abcdefghij
- Related Articles
- How to resize an array in Java?
- Is it possible to override toString method in an array using Java?
- How to resize an Image C#?
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?
- Check if it is possible to sort the array after rotating it in Python
- Check if it is possible to sort an array with conditional swapping of adjacent allowed in Python
- JavaScript Program to Check if it is possible to sort the array after rotating it
- Is it possible to predict the occurrence of an earthquake?
- Is it possible to use MongoDB to query for entries that have a particular value in a field in an object in an array?
- Why is it faster to process a sorted array than an unsorted array in C++?
- Is it possible to assign a numeric value to an enum in Java?
- Maximum possible XOR of every element in an array with another array in C++
- Is it possible to change values of the array when doing foreach() in javascript?
- Maximum possible difference of two subsets of an array in C++

Advertisements