What do the angle brackets after the class name mean in a variable declaration?

I've been programming in Delphi for a while, but I've never come across the syntax I found in a question here on SO. There was this syntax:

var Dic: TDictionary<Integer,string>;


I have never seen <type, type>

. What does it mean? When and where can it be used? I didn't find anything because Google omits characters like "<", ">".


source to share

2 answers

This is the syntax used for generics. Generics allows you to define classes that are parameterized by type.

You can read all about it in the Delphi documentation . You can also find the Wikipedia page. It gives a broader overview of the concept of general programming.



In many languages, usually this is mapping or template creation, Delphi calls these generics and an example of declaring them can be seen here

  TPair<Tkey,TValue> = class   // TKey and TValue are type parameters
    FKey: TKey;
    FValue: TValue;
    function GetValue: TValue;

function TPair<TKey,TValue>.GetValue: TValue;
  Result := FValue;


As your specific example, a dictionary is used that will map integers to strings.



All Articles