0

From the C# Language specification:

A type that includes at least one type argument is called a constructed type. A constructed type can be used in most places in the language in which a type name can appear

What I understand from this sentence is that including a type argument (even in the case in which more are required) is sufficient for a generic type to be called a 'constructed type' and being so, to be used in a type declaration.

Can you provide an example of a generic type with multiple type parameters that is constructed by specifying only one argument and is used where a type name can appear?

Edit 1

Probably the definition should be read as:

A type that includes all the required type arguments is called a constructed type.

That means: a generic definition comes with a certain number of type parameters. A constructed type is created by passing all the required parameters, either as open types or closded types.

Moreover, we can also have sort of 'overload' of generic types, where Queue is another type from Queue<> (and from Queue<,>, Queue<,,> etc. etc.).

namespace Widgets 
{
    class Queue {...}
    class Queue<TElement> {...}
}

Each type having its set of parameters; to identify a type, you have to use the exact number of parameters required, not "at least one". So maybe "at least one" means then when you see a declaration with "at least one" type arguments you can tell that that is a constructed generic.

AgostinoX
  • 7,477
  • 20
  • 77
  • 137
  • 2
    *generic type with multiple type parameters that is constructed by specify only one argument* There is no grammar for that. You either specify none `C<,,,>` or all of them `C`. You can not specify only some `C`. – user4003407 Oct 03 '19 at 23:51
  • The question of "open types" is already handled. https://stackoverflow.com/questions/2173107/what-exactly-is-an-open-generic-type-in-net – Holger Oct 05 '19 at 09:58

2 Answers2

0

The abstract Form like List< T > is called a generic type The concrete Form like List< int > or List< string > is called a constructed type.

So, you cannot use something like List< T > x = new List< T >(); You have to take List< int > x = new List< int ();

So the constructed name can appear, where Typenames usually appear

The number of parameters doesn't matter. A generic type always has a mininimum of 1 parameter. Number of arguments in generic and concrete type have to match. They just gave a definition: If something has a type-argument, it must be a concrete type and cannot be something else. It does not say, everything with a type-argument is valid.

Holger
  • 2,446
  • 1
  • 14
  • 13
  • But right after the definition that i quoted, we have: "A constructed type is an open type if and only if one or more of its type arguments is an open type. A constructed nested type is an open type if and only if one or more of its type arguments or the type arguments of its containing type(s) is an open type." So a constructed type *can* still be open. How can it be? And how can such a constructed type appear where types are required? – AgostinoX Oct 04 '19 at 08:21
  • @AgostinoX Just above your quote is: "A type parameter defines an open type.". `class C { List field; }`. `List` here is constructed and is open type. – user4003407 Oct 04 '19 at 18:09
0

The question of "open types" is already handled.

What exactly is an "open generic type" in .NET?

typeof(List<>)

is an "open" or generic type. The arguments are not yet set. It's open to construct types: "constructed types".

With

typeof(List<>).MakeGenericType(typeof(int));

you achieve the same as with

typeof(List<int>)
Holger
  • 2,446
  • 1
  • 14
  • 13
  • I read many questions like the one you said,my question is about 'constructed' concept, not open/closed concept. – AgostinoX Oct 05 '19 at 10:08