VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-how-to-change-the-size-of-one-dimensional-array/

⇱ C#| How to change the size of one-dimensional array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C#| How to change the size of one-dimensional array

Last Updated : 11 Jul, 2025
Array.Resize(T[], Int32) Method is used to resize the number of elements present in the array. Or in other words, this method is used to change the number of elements of a one-dimensional array to the specified new size. It resizes the only 1-D array, not multidimensional array. Syntax:
public static void Resize<T> (ref T[] array, int newSize);
Parameters:
array: It is a one-dimensional, zero-based array to resize, or null to create a new array with the specified size. newsize: It is the size of the new array.
Exception:If the value of nsize is less than zero, then this method will give ArgumentOutOfRangeException. Note: This method is an O(n) operation, where n is new size. Below given are some examples to understand the implementation in a better way: Example 1:
Output:
Original Array:
C#
Java
C++
Python
HTML
CSS
JavaScript
Length of myarray: 7

New array is less than myarray:
C#
Java
C++
Python
Example 2:
Output:
Original Array:
C#
C++
Ruby
Java
PHP
Perl
Length of myarray: 6

New array is greater than myarray:
C#
C++
Ruby
Java
PHP
Perl




Length of New Array: 10
Reference: https://learn.microsoft.com/en-us/dotnet/api/system.array.resize?view=netcore-2.1
Comment
Article Tags:

Explore