我有以下代码向字典添加一些值。将项目添加到字典时方法可以Linq.Contains
抛出吗?System.InvalidOperationException
"Collection was modified; enumeration operation may not execute."
private static object _lock = new object();
private static Dictionary<Type, A> _dic = new Dictionary<Type, A>();
public static AddNewValue(Type t, A value)
{
if ( !_dic.Keys.Contains( t ) )
{
lock ( _lock )
{
if ( !_dic.Keys.Contains( t ) )
{
_dic.Add( t, value );
}
}
}
}