求助:C# Dictionary<string,object>遇到的问题。
异常描述:
System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)
public static void CloneKeyTo(ASObject sourceASO, out ASObject desASO) { desASO = new ASObject(); string[] keys; lock (sourceASO.Keys) { keys = sourceASO.Keys.ToArray(); } foreach (string key in keys) { lock (sourceASO) { if (sourceASO.ContainsKey(key))//这里出异常,说key==null { desASO[key] = sourceASO[key]; } } } }
Dictionary<string,object> demoObj = new Dictionary<string,object>();demoObj[null]=1;//这是更加不可能的,直接异常。