是否有一个等效的字典可以接受字母数字作为键?在花了一些时间让你们帮助分配 UUID 值之后,我现在意识到字典只接受整数。我本来计划使用 UUID 作为 key 。
我的设计是针对总账的 - 我的账本成员被初始化为ledger := Dictionary new
,我希望做一些类似的事情:
postTransaction: GLEntry
ledger at: GLEntry UID put: GLEntry
最佳答案
字典可以使用任何你喜欢的东西作为键。在字典中使用字符串作为键是很常见的。例如,在 Dolphin Smalltalk v6.x 中评估以下内容:
d := Dictionary new.
d
at: 'a' put: 'a string';
at: 'b' put: 'b string';
at: 'c' put: 'c string'.
Transcript
show: (d at: 'a'); cr;
show: (d at: 'b'); cr;
show: (d at: 'c'); cr
将导致
a string
b string
c string
显示在“脚本”窗口中。
分享并享受。
关于Smalltalk - 以字母数字为键的字典等效项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17439005/