详测 Generics Collections TDictionary(3): TPairEnumerator、TKeyEnumerator、TValueEnumerator、ExtractPair...

本文探讨了为什么在软件开发领域,有80%的程序员未能成为架构师的原因,深入剖析了技能差距、思维模式及职业路径选择等因素。
//这组功能没有多少实用价值
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Generics.Collections;

procedure TForm1.Button1Click(Sender: TObject);
var
  Dictionary: TDictionary<string,Integer>;
  ds: TDictionary<string,Integer>.TPairEnumerator;
  ks: TDictionary<string,Integer>.TKeyEnumerator;
  vs: TDictionary<string,Integer>.TValueEnumerator;
begin
  Dictionary := TDictionary<string,Integer>.Create();

  Dictionary.Add('n1', 111);
  Dictionary.Add('n2', 222);
  Dictionary.Add('n3', 333);


  ds := Dictionary.GetEnumerator;
  while ds.MoveNext do ShowMessageFmt('%s:%d', [ds.Current.Key, ds.Current.Value]);
  {n2:222  n3:333  n1:111}

  ks := Dictionary.Keys.GetEnumerator;
  while ks.MoveNext do ShowMessageFmt('%s', [ks.Current]);
  {n2  n3  n1}

  vs := Dictionary.Values.GetEnumerator;
  while vs.MoveNext do ShowMessageFmt('%d', [vs.Current]);
  {222  333  111}    

  { ExtractPair 应是提取元素, 但它的返回值有些问题; 该函数源码有待修改 }
  Dictionary.ExtractPair('n1');
  ShowMessage(IntToStr(Dictionary.Count)); {2}
  
  Dictionary.Free;
end;

end.

 
 
 
 
 

 

 

  

转载于:https://my.oschina.net/hermer/blog/320438

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值