What will be the memory address of arr
, when I am doing arr = new T[size]
twice in the same scope while varying size
?
Does the memory expands to new size and starting address
of arr
remains the same?
Or if the new memory allocation happens then the previous data get copied to new memory location?
using System;
class HelloWorld
{
static void Main ()
{
byte[] arr;
arr = new byte[6];
arr[2] = 6;
Console.WriteLine ("len = {0}\n{1}", arr.Length, arr[2]);
arr = new byte[10];
arr[2] = 10;
Console.WriteLine ("len = {0}\n{1}", arr.Length, arr[2]);
}
}