But I do not understand why there is no object? Is it also a reference type?
Yes, both double[] and object are reference types, so null implicitly converted to both of them. However, overloading elements usually favors more specific types, so the double[] constructor is used. See Section 7.5.3 of the C # Specification for details (and the boy has many details).
In particular, from section 7.5.3.5:
Given the two different types T1 and T2, T1 is a better conversion goal than T2 if at least one of the following is true:
- There is an implicit conversion from T1 to T2, and there is no implicit conversion from T2 to T1.
In this case, here T1 double[] and T2 is object . There is an implicit conversion from double[] to object , but an implicit conversion from object to double[] , so double[] is a better conversion goal than object .
If you want to force the use of the object constructor, just click:
D myD = new D((object) null);
Jon Skeet Feb 09 '14 at 20:52 2014-02-09 20:52
source share