delphi – 是否有一个简单的方式来复制TDictionary内容到另一个
发布时间:2020-12-15 04:30:17 所属栏目:大数据 来源:网络整理
导读:有没有一种方法或简单的方式如何将一个TDictionary内容复制到另一个? 假设我有以下声明 type TItemKey = record ItemID: Integer; ItemType: Integer; end; TItemData = record Name: string; Surname: string; end; TItems = TDictionaryTItemKey,TItemDat
有没有一种方法或简单的方式如何将一个TDictionary内容复制到另一个?
假设我有以下声明 type TItemKey = record ItemID: Integer; ItemType: Integer; end; TItemData = record Name: string; Surname: string; end; TItems = TDictionary<TItemKey,TItemData>; var // the Source and Target have the same types Source,Target: TItems; begin // I can't find the way how to copy source to target end; 我想将资源1:1复制到目标.有这样的方法吗? 谢谢! 解决方法
TDictionary有一个构造函数,允许您传递另一个集合对象,通过复制原始内容来创建新集合对象.你在找什么?
constructor Create(Collection: TEnumerable<TPair<TKey,TValue>>); overload; 所以你会用 Target := TItems.Create(Source); Target将被创建为Source的副本(或至少包含Source中的所有项目). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |