0

An array of T, a pointer to T, and a reference to T (represented as T[], T*, and T& respectively by Type.ToString) all share the similarity that they are constructed from an "element" type (which can be returned by Type.GetElementType). What is the correct term to address all these types? I am inclined to say "derived" or "constructed" types, but the former can be confused with inheritance and the latter with generics. Multidimensional arrays could also fall under the term.

  • FWIW, in C++ they're called compound types. I have no idea what they call them in C# but you could check that it's not that. – Lightness Races with Monica Feb 23 '16 at 16:20
  • @PreferenceBean If I remember correctly, classes and structs are called compound types by the specification. – IllidanS4 wants Monica back Feb 23 '16 at 17:05
  • 1
    @RobertHarvey The location of the ampersand is quite an important fact. An ampersand before a variable is indeed the "adress of" operator, which is present in both C# and C++. However, an ampersand after a type marks a byref type in .NET methods and CIL (not in C#, where it is marked with ref before it). Hope I've made it clear. – IllidanS4 wants Monica back Feb 23 '16 at 20:15
  • 1
    You're making this much harder than it is. The answer to your basic question is "No, there is no term that encompasses all of these things." – Robert Harvey Feb 23 '16 at 20:20
  • 3
    Not sure what you need the term for, but if it's so obscure that nobody can recognize it, it's not going to be of much use in documentation unless you explain the term first. Much like a joke; if you have to explain the joke, it's not a very good joke. – Robert Harvey Feb 23 '16 at 20:23
2

Generally, functions that take a type and return another type are called type constructors.

That term should be well known amongst functional languages, but less so in mainstream languages - often because the array notation is the only one used.

1

In C#, T[] can be referred to as arrays or "covariant arrays", which both C# and Java have. Some language critiques think that the covariant arrays were a mistake, and would have been different had generics been in the language from the start.

C# does not have "reference to T" (e.g. T& as we find in C++). While you can take the address of something, that becomes a pointer type (like in C). C# has out and ref parameters, but C# considers the type of out int abc as simply int (not int&, which doesn't exist in C#) that must be assigned before leaving the method normally.

C# does have pointers, which can only be used in an unsafe context. While arrays are a "managed" type (i.e. garbage collected and type-safe), pointers are not. You can take the address of an array element into a pointer, but to use it properly, you would have to pin the array so that the runtime/gc doesn't move or remove it, as in some sense this is mixing managed and unmanaged types.

Thus, I don't think there is an umbrella term in C# for these three types, as one isn't supported, and the other two are managed vs. unmanaged, which can be related, but are rather different beasts.

  • Reference Types in C# – Robert Harvey Feb 23 '16 at 18:41
  • 2
    @RobertHarvey He probably meant references (also known as managed pointers and byrefs), not reference types. C# supports references in a very limited way, only via ref parameters and arguments. However, .NET fully supports manipulation with references like C++. – IllidanS4 wants Monica back Feb 23 '16 at 18:43
  • @RobertHarvey, thanks for the "reference" (ar ar) ;) What the language is calling reference types, in the parlance of the OP, would be just T (where T extends Object (and not value type)). – Erik Eidt Feb 23 '16 at 20:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.