c# - System.Array does not support Add(), so how does collection initializer work? -


in c# can initialize array so:

var example = new int[] { 1, 4, 3 }; 

as quoted in custom collection initializers:

the collection object collection initializer applied must of type implements system.collections.ienumerable or compile-time error occurs. each specified element in order, collection initializer invokes add method on target object expression list of element initializer argument list, applying normal overload resolution each invocation. thus, collection object must contain applicable add method each element initializer.

but cannot add system.array, 1 has create new larger array each added item, not performance. how c# work when using collection initializer on array? wonder if write class internal array supports collection initializer.

array isn't custom collection. it's array. array initializers pre-date collection initializers, , inspired syntax.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -