How to clear part of array in C#

1 Answer

0 votes
using System;

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



/*
run:

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

*/

 



answered Aug 4, 2022 by avibootz

Related questions

1 answer 201 views
201 views asked May 12, 2021 by avibootz
1 answer 193 views
193 views asked Sep 19, 2023 by avibootz
1 answer 272 views
2 answers 425 views
...