Array.Resize<'T> Method ('T[], Int32)

 

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<'T> : 
        array:'T[] byref *
        newSize:int -> unit

Parameters

array
Type: 'T[]

The one-dimensional, zero-based array to resize, or null to create a new array with the specified size.

newSize
Type: System.Int32

The size of the new array.

Type Parameters

T

The type of the elements of the array.

Exception Condition
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 null, 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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: