C# Array Resize

8
27



Shows the performance cost with re sizing C# arrays. Re-sizing array preserve’s the original data but has to instantiate a new array and copy all of the elements into that array.

Nguồn:https://wijstaanvooronzegrondrechten.org/

8 COMMENTS

  1. Nice. In C++ most programmers totally deprecate arrays, and pretty much always want you to use vector unless you are absolutely positively definitely sure that the size by definition can never change — is there a similar extreme prejudice among C# people towards list<T> versus T[ ] ?

  2. int[] ages = new int[] { 25, 27, 23, 34, 34 };
                int[] temp =new int[ages.Length+1];
                for (int i = 0; i < ages.Length; i++)
                {
                 
                    temp[i] = ages[i];
                    ages = temp;
                    ages[5] = 99;
    }

    is there any mistake??????????
    when we write that code what line should we write in console.write(ages[i]); or  console.write(temp[i]);
    i try to write both line of console but it give me only 1st and last value in screen will you explain a little more ?????????
    output:
    25 0 0 0 0 0 99

LEAVE A REPLY

Please enter your comment!
Please enter your name here