Re: Array.Clear vs List<>.Clear

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



That's more or less what I wound up doing anyway, but curiosity got the better of me, and there's rarely harm in asking.

Lee Crabtree

Nicholas Paldino [.NET/C# MVP] wrote:
Lee,

There isn't a mechanism to do this, but writing your own is easy:

public static void ClearList<T>(List<T> list, int index, int length)
{
// Cycle through the list and set the item to the default.
for (; index < (index + length); ++index)
{
// Set the item in the list to the default value.
list[index] = default(T);
}
}


.