Array - ClearAll
A T[] extension method that clears all described by @this.
public static void Main() { int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (int i = 0; i < 9; i++) { Console.Write("{0} ", numbers[i]); } Console.WriteLine("\n\nAfter ClearAll()\n"); // C# Extension Method: Array - ClearAll numbers.ClearAll(); for (int i = 0; i < 9; i++) { Console.Write("{0} ", numbers[i]); } }
View Source
using System; public static partial class Extensions { /// <summary> /// A T[] extension method that clears all described by @this. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="this">The @this to act on.</param> /// ### /// <returns>.</returns> public static void ClearAll<T>(this T[] @this) { Array.Clear(@this, 0, @this.Length); } }