Resize array in C# later in the program -


i not sure if possible in c# i'm having variable defined in

 public partial class form1 : form  {...    ...     #region used variables     public ulong[] logp = {0,0,0,0,0,0,0,0}   ....   .. 

then later in program want have option adjust size in program before main routines launch on , calculations

because test vaious sets of numbers , array sizes have option resize array, each test (but array isnt bound single procedure, global variable needs resizable.

as whole program @ various parts using array, (under various functions) how should put part

    ulong [] sump = new ulong[numericupdown.valeu]; 

so change global variable size ?

you cannot resize array; must declare new array of desired size , copy contents of original array new array.

update: don't array.resize - doesn't resize array (as method name suggest), creates new array , replaces reference:

    static void main(string[] args)     {         int[] a1 = new int[] { 1, 2, 3 };         int[] a2 = a1;          console.writeline("a1 length: {0}", a1.length); // 3         console.writeline("a2 length: {0}", a2.length); // 3         array.resize(ref a1, 10);         console.writeline("a1 length: {0}", a1.length); // 10         console.writeline("a2 length: {0}", a2.length); // 3 - not          console.readline();     } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -