lim*_*imp 7 associative-array d
这个问题非常明显; 我希望能够在实际插入之前检查关联数组是否包含我将要(可能)插入的值.没有搜索,有没有一种简单的方法可以做到这一点dict.keys
?也许是这样的if (dict.contains(val)) ...
?
要测试密钥是否在关联数组中,请使用in
运算符:
string[int] aa;
string* ps = 100 in aa;
if(ps)
{
// 100 is a key in aa, ps is a pointer to the corresponding value
}
else
{
// 100 is not a key in aa
}
Run Code Online (Sandbox Code Playgroud)
要测试值是否存在,您必须搜索aa.values
.