Spec#, nullables and more

Simen kjaeraas simen.kjaras at gmail.com
Sat Nov 6 02:20:24 PDT 2010


Walter Bright <newshound2 at digitalmars.com> wrote:

> Consider non-nullable type T:
>
>    T[] a = new T[4];

As others have pointed out, this would be impossible for a proper
non-nullable type. The only ways to create an array of non-nullable
elements would be a literal, concatenation with non-nullable elements,
or casting an existing array of nullable elements.

You do not have write access to the length of an array of non-nullable
elements, so that you cannot increase the length (thus adding null
elements). You can decrease the length by slicing.

This way, it should be impossible to have elements of our array that are
null.

-- 
Simen


More information about the Digitalmars-d mailing list