简体   繁体   中英

How does an array in C# gets derived from System.Array?

We know how to define array like below but how does it gets derived from System.Array ?

int[] intArray = new int[] { 2, 4, 7 };

The above example is a simple int array but imagine I have Student class and I make an array of students, that will still get derived from System.Array .

Is the above code declaration some kind of shortcut for a fully qualified declaration?

The System.Array type

The type System.Array is the abstract base type of all array types. An implicit reference conversion (Implicit reference conversions) exists from any array type to System.Array, and an explicit reference conversion (Explicit reference conversions) exists from System.Array to any array type. Note that System.Array is not itself an array_type. Rather, it is a class_type from which all array_types are derived.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/arrays#the-systemarray-type

Is the above code declaration some kind of shortcut for a fully qualified declaration?

No. It's baked into the language that you declare array types by adding [] to other types. Generics didn't exist in the language initially or int[] might have been shorthand for Array<int> or somesuch.

Many of the features in C# are part of the language and are converted into the proper types or abstractions of types in the compile step. int, itself, is Int32 in the framework. VB.NET is even more rife with VB-ish shortcuts.

REMOVED link from wrong question. May edit again later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM