2 Replies - 11595 Views - Last Post: 02 December 2011 - 02:14 PM

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Resize a multidimensional array

Posted 06 November 2007 - 04:24 PM

Description: This method required 3 items: 1) The array you want to resize 2) # of columns you want #) # of rows you want This is a method for resizing a multi dimensional array. In VB.Net you have ReDim, in C# you can use Array.Resize, but theres nothing to resize a multi-dimensional array in C# TEST
/// 
/// Mthod for resizing a multi dimensional array
/// 
/// Original array you want to resize
/// # of columns in the new array
/// # of rows in the new array
private void ResizeArray(ref string[,] original, int cols, int rows)
{
    //create a new 2 dimensional array with
    //the size we want
    string[,] newArray = new string[rows, cols];
    //copy the contents of the old array to the new one
    Array.Copy(original, newArray, original.Length);
    //set the original to the new array
    original = newArray;
}

//Example Usage

//This example resizes the list array
//to be 2 columns and 10 rows
ResizeArray(list,2,10);


Is This A Good Question/Topic? 0
  • +

Replies To: Resize a multidimensional array

#2 Wasim Akhter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 12-April 09

Re: Resize a multidimensional array

Posted 12 April 2009 - 12:08 PM


Was This Post Helpful? 0
  • +
  • -

#3 simf1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 02-December 11

Re: Resize a multidimensional array

Posted 02 December 2011 - 02:14 PM

This code work so well, if i want to increase an array. Thanks! But if i want to reduce the size of my array... an error occured. How can I resolve it. Do you have a idea? Could you help me? Ex. try this... ResizeArray(list,2,10); //and after... ResizeArray(list,1,3); //this will generate an error.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1