Array.Clear vs List<>.Clear



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
.



Relevant Pages

  • Re: Surprise in array concatenation
    ... >> You are mixing inadequate and inconsistent models. ... > decide, mathematically, whether consistency is consistent.) ... > build your own array abstraction, use use Ada.Containers.Vectors, ... The idiom you trying to push for has a clear application area. ...
    (comp.lang.ada)
  • Re: @ARGV array incorrect when calling perl program from system
    ... If there is more than one argument in LIST, or if LIST is an array ... So of course '>' and 'logfile' is parsed to the script as script ... If this is really Posix' definition, then Posix is inconsistent. ...
    (comp.lang.perl.misc)
  • Re: How to find duplicate x,y points in x,y,z space???
    ... > I have an array of data where each row is an x, y, z point. ... > that some of the data might be inconsistent (same x, y, but different z ... Consolidator from the file exchange will find replicates ... The best material model of a cat is another, or preferably the same, cat. ...
    (comp.soft-sys.matlab)
  • Re: arbitrary indexes
    ... can't convert Array into Integer ... This seems a little inconsistent, it would seem better if it handled ... any arguments which were enumerables containing integers. ... Rick DeNatale ...
    (comp.lang.ruby)
  • Re: arbitrary indexes
    ... TypeError: can't convert Array into Integer ... This seems a little inconsistent, it would seem better if it handled ... any arguments which were enumerables containing integers. ...
    (comp.lang.ruby)

Loading