L
Lee Crabtree
This seems inconsistent and more than a little bizarre.
Array.Clear sets all elements of the array to their default values (0,
null, whatever), whereas List<>.Clear removes all items from the list.
That part makes a reasonable amount of sense, as you can't actually take
items away from an Array. However, there doesn't seem to be a way to
perform the same operation in one fell swoop on a List<>.
For example:
byte[] byteArr = new byte[10];
....things happen and bytes get set...
Array.Clear(byteArr, 0, 10);
Now all the bytes are set to 0.
But if you use a List<byte>:
List<byte> byteList = new List<byte>(new byte[10]);
....things happen and bytes get set...
There's no way to reset all the bytes, so you're forced to iterate over
the list. Now, I'm sure that the performance hit of having to run a for
loop across the list isn't incredible. But aside from the apparent
inconsistency, I have to wonder if there isn't some mechanism to do the
same thing to a generic List.
Lee Crabtree
Array.Clear sets all elements of the array to their default values (0,
null, whatever), whereas List<>.Clear removes all items from the list.
That part makes a reasonable amount of sense, as you can't actually take
items away from an Array. However, there doesn't seem to be a way to
perform the same operation in one fell swoop on a List<>.
For example:
byte[] byteArr = new byte[10];
....things happen and bytes get set...
Array.Clear(byteArr, 0, 10);
Now all the bytes are set to 0.
But if you use a List<byte>:
List<byte> byteList = new List<byte>(new byte[10]);
....things happen and bytes get set...
There's no way to reset all the bytes, so you're forced to iterate over
the list. Now, I'm sure that the performance hit of having to run a for
loop across the list isn't incredible. But aside from the apparent
inconsistency, I have to wonder if there isn't some mechanism to do the
same thing to a generic List.
Lee Crabtree