C# Array Resize() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Array.Resize changes which array your variable points to. It allocates a new array with the new length, copies elements from the old array, and writes that new reference back through a ref parameter.

Arrays themselves still have fixed length. Resize is sugar for “make a bigger/smaller array and keep my variable updated.” Prefer List<T> when you resize often.

This is a static member of System.Array. You call it with the class name, such as Array.Resize(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.

Syntax

Pass the array variable with ref and the new size.

C#
Array.Resize(ref nums, 8);
Array.Resize(ref nums, 2);
CallWhat it does
Array.Resize(ref nums, 8)New length 8; old values copied; new slots are default.
Array.Resize(ref nums, 2)New length 2; only the first two old values are kept.

Other variables that still reference the old array will not see the resize.

Library declarations
C#
public static void Resize<T>(ref T[] array, int newSize);

Parameters

ParameterDescription
arrayRequired. Passed by ref so the caller variable can be replaced.
newSizeRequired. New length (non-negative).

Return Value

Return ValueDescription
voidThe ref variable now references the new array.

C# Examples

Example 1 — Grow an Array

Expand length from 3 to 5 and show default-filled slots.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 1, 2, 3 };
        Array.Resize(ref nums, 5);

        Console.WriteLine("Length: " + nums.Length);
        Console.WriteLine(string.Join(", ", nums));
    }
}

How It Works

  1. ref required. Without ref, the caller could not see the new array.
  2. Copy prefix. 1, 2, 3 move into the new buffer.
  3. Defaults. New int slots are 0.
  4. New object. Length is now 5 on the replacement array.

Example 2 — Shrink and Truncate

Reduce length and drop trailing elements.

C#
using System;

class Program {
    static void Main() {
        string[] names = { "Ann", "Bob", "Cara", "Dan" };
        Array.Resize(ref names, 2);
        Console.WriteLine(string.Join(", ", names));
        Console.WriteLine("Length: " + names.Length);
    }
}

How It Works

  1. Keep prefix. Only the first two names survive.
  2. Cara/Dan dropped. They are not in the new array.
  3. Length updates. Variable now reports 2.
  4. Data loss. Shrinking discards the tail permanently (for this variable).

Example 3 — Old Reference Unchanged

Show that another variable still points at the pre-resize array.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 1, 2, 3 };
        int[] alias = nums;

        Array.Resize(ref nums, 5);

        Console.WriteLine("nums.Length  = " + nums.Length);
        Console.WriteLine("alias.Length = " + alias.Length);
    }
}

How It Works

  1. Shared at first. alias and nums began as one object.
  2. Resize retargets nums. Only the ref parameter is updated.
  3. alias stays old. It still has length 3.
  4. Mind aliases. This surprises people coming from resizable lists.

Frequently Asked Questions

No. It allocates a new array and updates your ref variable to point at it.
So the method can replace the caller’s array reference with the new array.
They are set to default(T): 0 for int, null for reference types.
Only elements that fit in the new length are copied; the rest are discarded from the new array.
Prefer List<T> for frequent growth. Resize allocates each time.

Next: Reverse()

Reverse the order of elements in an array (or a range) in place with System.Array.

Reverse() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful