c# - How to assign 0 to whole array -


i have array. int[] array = new int[10];. want assign '0' whole array without using loop means 0 stored in of indexes. how it.

after creation items of array have default values, 0 int. so, don't need here.

from arrays (c# programming guide):

the default values of numeric array elements set zero, , reference elements set null.


also c# specification 12.2 array creation

elements of arrays created array-creation-expressions initialized default value.

5.2 default values

for variable of value-type, default value same value computed value-type's default constructor

4.1.2 default constructors

for sbyte, byte, short, ushort, int, uint, long, , ulong, default value 0.


but after assigning other values want indexes 0 again how it?

update: can use array.clear:

sets range of elements in array zero, false, or null, depending on element type.

in case:

array.clear(array, 0, array.length); 

consider use list<int> instead of array - allows add/remove items dynamically.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -