Because when you allocate an array of reference types all you get is an array of references and therefore the allocation is always a known thing. With value type arrays, the memory for the value type is allocated inline and therefore needds to be initialized. If you provide a default constructor (or field initializer) that those would have to run as a result. This creates a potential hidden cost in array allocation for value types. Also, you can obtain value types from unmanaged code which certainly won't have run your default constructor code.
Why don't you put your initialization in a non-default constructor?
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
I read your article and it was very interesting *however*, it appears that
the main reason not to allow a default constructor on a struct is because
you can have code in the constructor that could delay the creation of the
struc.
The problem that I have with this is "So What?" let the constructor take a
year to initialize, who cares. If I wanted to, I could have a constructor in
a regular class that takes 3 years to run and nobody cares, why this sudden
urge not to allow this from happening on a struct?
My guess is that something must be going on in the runtime that would get
screwed up if they let this happen, perhaps all application using the
runtime will stop working, perhaps, the garage collector would stop cleaning
while this goes on, I have no idea but that is exactly what I would like to
find out, do you know what it is?