Array.Resize(T) Method

Changes the number of elements of a one-dimensional array to the specified new size.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

static member Resize : 
        array:'T[] byref * 
        newSize:int -> unit

Type Parameters

T

The type of the elements of the array.

Parameters

array
Type: T[]

The one-dimensional, zero-based array to resize, or a null reference (Nothing in Visual Basic) to create a new array with the specified size.

newSize
Type: System.Int32

The size of the new array.

ExceptionCondition
ArgumentOutOfRangeException

newSize is less than zero.

This method allocates a new array with the specified size, copies elements from the old array to the new one, and then replaces the old array with the new one. array must be a one-dimensional array.

If array is a null reference (Nothing in Visual Basic), this method creates a new array with the specified size.

If newSize is greater than the Length of the old array, a new array is allocated and all the elements are copied from the old array to the new one. If newSize is less than the Length of the old array, a new array is allocated and elements are copied from the old array to the new one until the new one is filled; the rest of the elements in the old array are ignored. If newSize is equal to the Length of the old array, this method does nothing.

This method is an O(n) operation, where n is newSize.

The Resize(T) method resizes a one-dimensional array only. The Array class does not include a method for resizing multi-dimensional arrays. To do this, you must either provide your own code or call a special-purpose method in a third-party library. The following code illustrates one possible implementation for a method that resizes an array of n dimensions.

No code example is currently available or this language may not be supported.

The following example shows how resizing affects the array.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft