How to set all int array elements to zero in C#

1 Answer

0 votes
using System;
 
public class Program
{
    public static void Main(string[] args)
    {
        int[] arr = {2, 4, 5, 0, 9, 1, 7};

        Array.Clear(arr, 0, arr.Length);
        
        for (int i = 0; i < arr.Length; i++) {
            Console.Write(arr[i] + " ");
        }
    }
}
 
 
 
/*
run:
 
0 0 0 0 0 0 0 
 
*/

 



answered Feb 12, 2024 by avibootz

Related questions

...