Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Replace a C# array with a new array of different size
To replace a C# aray with a new array, use the Array.Resize.
Withing that, set the size of the new array −
Array.Resize<char>(ref arr, 4);
Now add the new elements to the array as shown below −
Example
using System;
class Program {
static void Main() {
char[] arr = new char[5];
arr[0] = 'J';
arr[1] = 'A';
Array.Resize<char>(ref arr, 4);
// Set value for new elements
arr[2] = 'C';
arr[3] = 'K';
Console.WriteLine("Updated Array : "+ new string(arr));
}
}
Output
Updated Array : JACK
Advertisements
