

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
- Related Questions & Answers
- How do you create an empty list in Java?
- How do I empty an array in JavaScript?
- How do you convert an ArrayList to an array in Java?
- How do you limit an array sub-element in MongoDB?
- How do you perform an AND query on an array in MongoDB?
- How do you sort an array in C# in ascending order?
- How do you sort an array in C# in descending order?
- How do you find the length of an array in C#?
- How do you print the content of an array in Java?
- How to empty an array in Java
- How to empty an array in JavaScript?
- In Javascript how to empty an array
- How do you convert a list collection into an array in C#?
- How do you check if a variable is an array in JavaScript?
- How do you remove an array element by its index in MongoDB
Advertisements