Reusing An Array In C#

Blog Date 13 July 2021

The Code

        string[] ParamNames = {"Fred", "Sue", "John", "Karen"};
        object[] ParamValues = {36, "Out", "Round", 45};

         ParamNames = new string[] {"Jane", "Louse", "Karl", "Cyndy"};
         ParamValues = new object[] {33, "In", "Square", 43};

The Explanation

Declaring an array we already know. But rather than declare and create a new array we can use the pervious one if the code allows. In which case we use the "new" method. You could use "new []..." but I find it better from a readable point of view and it can cause errors with objects to use "new string[]..." and/or "new object[]..."

Reader's Comments

Post Your Comment Posts/Links Rules



Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below

Admin Ren's Biking Blog