如何为Activator.CreateInstance设置字典大小?

时间:2012-08-08 02:06:50

标签: c#

我想使用Activator.CreateInstance设置字典的初始大小,请问是什么语法?

var collection = Activator.CreateInstance(someDictionaryType) as IDictionary; 

1 个答案:

答案 0 :(得分:3)

如果您想调用Dictionary constructor with an int parameter representing capacity,请使用单个元素传递object数组 - 大小:

var collection = Activator.CreateInstance(someDictionaryType, new object[] {123}) as IDictionary;