加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 提供给.NET泛型构造函数的类型参数,但仍然会导致错误,如果

发布时间:2020-12-16 00:07:37 所属栏目:百科 来源:网络整理
导读:我的ASP.NET MVC 4 Razor应用程序中有一些看似无问题的代码片段: @{ IDictionary htmlAttributes = new Dictionarystring,string();} 这是产生错误, “Using the generic type ‘System.Collections.Generic.IDictionary’ requires 2 type arguments”. 任
我的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接口,请确保其命名空间(System.Collections)在范围内.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读