How to set a range of elements in an array to zero in VB.NET

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        for (int i = 0; i < arr.Length; i++) {
            Console.Write("{0} ", arr[i]);
        }
        Console.WriteLine();

        Array.Clear(arr, 3, 2);

        for (int i = 0; i < arr.Length; i++) {
            Console.Write("{0} ", arr[i]);
        }
    }
}



/*
run:

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

*/

 



answered Dec 3, 2020 by avibootz
...