Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 751 Bytes

Any.ReDim.md

File metadata and controls

50 lines (37 loc) · 751 Bytes

Any.ReDim

Reallocates storage space for an array variable.


Example 1 ( Shrink space )

var d2 = new int[3, 3]
{
    { 0, 1, 2 },
    { 3, 4, 5 },
    { 6, 7, 8 }
};
Any.ReDim(ref d2, 2, 2);

for (int i = 0; i < d2.GetLength(0); i++)
{
    var row = new int[d2.GetLength(1)].Let(j => d2[i, j]);
    Console.WriteLine(row.Join(", "));
}

0, 1
3, 4


Example 2 ( Expand space )

var d2 = new int[3, 3]
{
    { 0, 1, 2 },
    { 3, 4, 5 },
    { 6, 7, 8 }
};
Any.ReDim(ref d2, 4, 4);

for (int i = 0; i < d2.GetLength(0); i++)
{
    var row = new int[d2.GetLength(1)].Let(j => d2[i, j]);
    Console.WriteLine(row.Join(", "));
}

0, 1, 2, 0
3, 4, 5, 0
6, 7, 8, 0
0, 0, 0, 0