c# dictionary 给某键值赋值之前是否一定要add此键值? DictionarykeyType, valueType dict = new ....;void SetKeyValue(key, value){ if (!dict.Contain(key)) dict.Add(key, value); else dict[key] = value;}
c# dictionary 给某键值赋值之前是否一定要add此键值?
Dictionary<keyType, valueType> dict = new ....;
void SetKeyValue(key, value)
{
if (!dict.Contain(key))
dict.Add(key, value);
else
dict[key] = value;
}