我的 ASP.NET MVC 4 Razor 应用程序中有这段看似没有问题的代码:
@{
IDictionary htmlAttributes = new Dictionary<string, string>();
}
这会产生错误,
"Using the generic type 'System.Collections.Generic.IDictionary' requires 2 type arguments".
有人知道发生了什么事吗?
最佳答案
你还需要把它放在左边:
IDictionary<string, string> htmlAttributes = new Dictionary<string, string>();
请注意,错误消息是在谈论 IDictionary
,而不是 Dictionary
。
或者,如果您确实想要非通用的 IDictionary
接口(interface),确保其命名空间 (System.Collections
) 在范围内。
关于c# - 提供给 .NET 通用构造函数的类型参数,但仍然会导致错误,就好像没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16359456/