Resize Method (Static Method In Array Class)


Syntax for Resize Method is  :- Resize<int>(ref arrayname,newsize)

Resize method expand the size of  the specified array. Best thing is that it preserves the earlier element values in an array and provides the capability to assign new element values.
--------------------------------------------------------------------------------------------------------
using System;
class ResizeMethod
{
static void Main()
  {
  int[] arr = {1,2,3};  
Console.WriteLine("Length before using Resize method " + arr.Length);
Console.WriteLine("--------------------------------------");

foreach(int i in arr)
{ Console.Write(i + "\t"); }

Console.WriteLine("\n--------------------------------------");
Array.Resize<int>(ref arr, 5);
arr[3] = 4;
arr[4] = 5;
Console.WriteLine("Length after using Resize method " + arr.Length);
Console.WriteLine("--------------------------------------");

foreach(int i in arr)
{ Console.Write(i + "\t"); }

Console.WriteLine("\n--------------------------------------");
}
}
--------------------------------------------------------------------------------------------------------

Resize Method (Static Method In Array Class) Resize Method (Static Method In Array Class) Reviewed by Baljeet Singh on 07:51 Rating: 5

No comments:

Powered by Blogger.