Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question answers itself. <strong>Array types are themselves a form of generic typing.</strong> Had we put a generic type system in CLR v1.0, I'd be willing to bet that there would be no special array type, there would just be <code>Array&lt;T&gt;</code> along with <code>List&lt;T&gt;</code> and so on. Since the first version of the CLR did not have generic types, we put into it the most important and obvious generic type, the array type. And as a result, there is a whole bunch of special-purpose code in there just to handle arrays, the one generic type the CLR supported in v1.0.</p> <p>Since arrays are essentially a generic type, your question answers itself: the reason for generic types in general is the same reason that motivates the creation of the array type pattern. That is: an array type <em>amplifies the ability of its underlying type in a specific way</em>. </p> <p>An int represents a number. An int[] represents a collection of numbers; we have <em>amplified</em> the notion of number to the notion of a collection of numbers. A Customer represents a customer. A Customer[] represents the notion of a collection of customers. We have amplified the notion of customer to the notion of collection of customer. <strong>The mapping from type T to type T[] represents the abstract notion of generically amplifying an instance of a type to a collection of instances of the type.</strong></p> <p>That same justification motivates all generic types. The <code>Nullable&lt;T&gt;</code> type amplifies a type to the notion of "this thing might be an instance of the type". The <code>IComparable&lt;T&gt;</code> type amplifies a type to the notion of "an instance of this type can be ordered with respect to another instance". And so on. Each generic type is just like the array pattern: it represents the amplification of a type into a new type which provides new operations on that type.</p> <p>In short: <strong>the purpose of the generic type system is to enable you to invent your own type amplifications, and manipulate those amplifications using the type system</strong>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload