I have been programming in Delphi for a while, but I never ran across a syntax that I found in a question here on SO. There was this syntax:
var Dic: TDictionary<Integer,string>;
I've never seen the <type, type>
. What does it mean? When and where can it be used? I found nothing, since Google omits chars like '<', '>'.
It is the syntax used for generics. Generics allow you to define classes that are parameterized by type.
You can read all about it in the Delphi documentation. You may also find the Wikipedia page useful. It gives a broader overview of the concept of generic programming.
In many languages, it's usually a mapping, or template instantiation, Delphi calls these generics, and an example of declaring them can be seen here:
type
TPair<Tkey,TValue> = class // TKey and TValue are type parameters
FKey: TKey;
FValue: TValue;
function GetValue: TValue;
end;
function TPair<TKey,TValue>.GetValue: TValue;
begin
Result := FValue;
end;
What your particular example is defining is a dictionary that will map integers to strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With