Clear array values using Array.Clear
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| C# Code Snippets |
| See also |
| edit |
This C# code snippet clears out the specified array values using Array.Clear.
using System; class ArrayClear { public static void Main() { int[] integers = { 1, 2, 3, 4, 5 }; DumpArray ("Before: ", integers); Array.Clear (integers, 1, 3); DumpArray ("After: ", integers); } public static void DumpArray (string title, int[] a) { Console.Write (title); for (int i = 0; i < a.Length; i++ ) { Console.Write("[{0}]: {1, -5}", i, a[i]); } Console.WriteLine(); } }
| Array.Clear example (program output) |
| Before: [0]: 1 [1]: 2 [2]: 3 [3]: 4 [4]: 5 After: [0]: 1 [1]: 0 [2]: 0 [3]: 0 [4]: 5 |