- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 to use the Clear method of array class in C#?
The Array.Clear class in C# clears i.e.zeros out all elements.
In the below example, we have first considered an array with 3 elements.
int[] arr = new int[] { 11, 40, 20};
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[] {11, 40, 20}; 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): 11 40 20 Array (After using Clear): 0 0 0
- Related Articles
- How to use the Clone() method of array class in C#?
- How to use the Copy(, ,) method of array class in C#
- How to use the CopyTo(,) method of array class in C#
- How to use the GetLength method of array class in C#?
- How to use the GetLongLength method of array class in C#?
- How to use the GetLowerBound method of array class in C#
- How to use the GetType method of array class in C#?
- How to use the GetUpperBound method of array class in C#?
- How to use the GetValue() method of array class in C#?
- How to use the IndexOf(,) method of array class in C#?
- How to use the Reverse() method of array class in C#
- How to use the SetValue(,) method of array class in C#?
- How to use the Sort() method of array class in C#?
- The clear() method of AbstractList class in Java
- The clear() method of Java AbstractCollection class

Advertisements