Does Array.Clear use default?
-
If one has
T[] a = new T[](something); ... Array.Clear(a,0,a.Length);
does Array.Clear use default(T)? The documentation for .NET 2.0 and 3.0 suggests that it doesn't (!):public static void Clear(Array array, int index, int length)
Sets a range of elements in the Array to zero, to false, or to a null reference (Nothing in Visual Basic), depending on the element type. If Array.Clear really does not use default(T), is there some a base class library method that does this:static void f(Array a, int index, int length) { for (int i = 0; i < a.Length; i++) { a[i] = default(T); } }
where T is the type of the array? Maybe this would be something in System.Collections.Generic in order to allow the method's implementation to get at T. It's easy enough to make my own method to do this but I'd just as soon not do it if something already exists in the base class library. -
If one has
T[] a = new T[](something); ... Array.Clear(a,0,a.Length);
does Array.Clear use default(T)? The documentation for .NET 2.0 and 3.0 suggests that it doesn't (!):public static void Clear(Array array, int index, int length)
Sets a range of elements in the Array to zero, to false, or to a null reference (Nothing in Visual Basic), depending on the element type. If Array.Clear really does not use default(T), is there some a base class library method that does this:static void f(Array a, int index, int length) { for (int i = 0; i < a.Length; i++) { a[i] = default(T); } }
where T is the type of the array? Maybe this would be something in System.Collections.Generic in order to allow the method's implementation to get at T. It's easy enough to make my own method to do this but I'd just as soon not do it if something already exists in the base class library.