Delphi TDictionary 简单用法


本文整理自网络,侵删。

 
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Generics.Collections;
var
{  Dictionary: TDictionary<LongWord, string>;
  aPair: TPair<LongWord, string>;}

   Dictionary: TDictionary<string, LongWord>;
  aPair: TPair<string, LongWord>;
begin
  {Dictionary := TDictionary<LongWord, string>.Create;
  Dictionary.add(1, 'First Item');
  Dictionary.add(2, 'Second Item');
  Dictionary.add(3, 'Third Item');
  Dictionary.add(4, 'Third Item');
  Dictionary.add(5, 'Forth Item');
  Dictionary.add(6, 'Fifth Item');

  for aPair in Dictionary do
    writeln(aPair.Value);
                           }


Dictionary := TDictionary<string, LongWord>.Create;
  Dictionary.AddOrSetValue('First Item',0);
  Dictionary.AddOrSetValue('Second Item',0);
  Dictionary.AddOrSetValue('Third Item',0);
  Dictionary.AddOrSetValue('Third Item',0);
  Dictionary.AddOrSetValue('Forth Item',0);
  Dictionary.AddOrSetValue('Fifth Item',0);

  for aPair in Dictionary do
   // writeln(aPair.Value);
    writeln(aPair.Key);
  readln;
end.

相关阅读 >>

Delphi10.3构造一个json数据的第三种方法,并格式化输出

Delphi 调用单元unit代码

Delphi 动态创建一个ipedit控件

Delphi中内嵌汇编

Delphi实现分割文本文件的小程序

Delphi生成随机字符串

Delphi 匿名管道

Delphi tlistview按指定列排序

Delphi 如何得到 winrar 处理解压缩文件的返回值 ?

Delphi snowflake一秒可生成500万id的分布式自增id算法―雪花算法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...