我想使用Activator.CreateInstance设置字典的初始大小,请问是什么语法?
var collection = Activator.CreateInstance(someDictionaryType) as IDictionary;
答案 0 :(得分:3)
如果您想调用Dictionary
constructor with an int parameter representing capacity,请使用单个元素传递object
数组 - 大小:
var collection = Activator.CreateInstance(someDictionaryType, new object[] {123}) as IDictionary;