 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you empty an array in C#?
To empty an array in C#, use the Array Clear() method: The Array.Clear method in C# clears i.e.zeros out all elements.
In the below example, we have first considered an array with three elements −
int[] arr = new int[] {88, 45, 76}; Now we have used the Array.Clear method to zero out all the arrays −
Array.Clear(arr, 0, arr.Length);
Let us see an example of Array.Clear method in c# −
Example
using System; class Program {    static void Main() {       int[] arr = new int[] {88, 45, 76};       Console.WriteLine("Array (Old):");       foreach (int val in arr) {          Console.WriteLine(val);       }       Array.Clear(arr, 0, arr.Length);       Console.WriteLine("Array (After using Clear):");       foreach (int val in arr) {          Console.WriteLine(val);       }    } }  Output
Array (Old): 88 45 76 Array (After using Clear): 0 0 0
Advertisements
 