How to use Array.Clear() to zero all the elements in int array with C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7 };
 
        Console.WriteLine(string.Join(" ", arr));
 
        Array.Clear(arr, 0, arr.Length);
 
        Console.WriteLine(string.Join(" ", arr));
    }
}



/*
run:

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

*/

 



answered Mar 5, 2017 by avibootz
edited Sep 19, 2023 by avibootz
...