In C# how to create a List<T> with a default count of zero? -
rookie question:
i have been experiencing minor bug in mvc2 application. able trace code:
list<stream2fieldtypes> stream2fieldtypes = new list<stream2fieldtypes>(); foreach (var item in stream.stream2fieldtypes) { stream2fieldtypes.add(item); }
the problem experiencing when instatiate new list, has count of one. i'm thinking due using constructor. tried this:
list<stream2fieldtypes> stream2fieldtypes; foreach (var item in stream.stream2fieldtypes) { stream2fieldtypes.add(item); }
but, of course not compile because of error on stream2fieldtypes.add(item);
. there way can create list<stream2fieldtypes>
, make sure count zero?
the problem experiencing when instatiate new list, has length of one
no, that's totally impossible. problem somewhere else , unrelated number of elements of newly instantiated list.
list<stream2fieldtypes> stream2fieldtypes = new list<stream2fieldtypes>();
stream2fieldtypes.count
0 @ point no matter (assuming of course single threaded sequential access list<t>
not thread-safe anyways it's safe assumption :-)).
Comments
Post a Comment