zoukankan      html  css  js  c++  java
  • 详测 Generics Collections TDictionary(3): TPairEnumerator、TKeyEnumerator、TValueEnumerator、ExtractPair

    //这组功能没有多少实用价值
    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.
    
  • 相关阅读:
    15、事例十五:纹理映射
    14、事例十四:材质:十二个材质球
    [luogu]P1084 疫情控制
    [luogu]P2502 [HAOI2006]旅行
    [luogu]P2053 [SCOI2007]修车
    线性相关/线性基
    [luogu]P3629 [APIO2010]巡逻
    [luogu]P3623 [APIO2008]免费道路
    权值线段树
    树链剖分
  • 原文地址:https://www.cnblogs.com/del/p/1580951.html
Copyright © 2011-2022 走看看