【问题标题】:Add dictionary that contains an array type to a dictionary将包含数组类型的字典添加到字典
【发布时间】:2013-03-25 11:11:43
【问题描述】:

我在将具有 Vector2 数组作为其值类型的字典放入作为类属性的字典时遇到问题:

Dictionary<string, Dictionary<string, Vector2[]>> foo = new Dictionary<string, Dictionary<string, Vector2[]>>();  // OK
foo.Add("bar", new Dictionary<string, Vector2[]>()); // OK

fooAttribute.add("bar", new Dictionary<string, Vector2[]>()); // NOT OK

属性声明为:

protected Dictionary<string, Dictionary<string, Vector2[]>> fooAttribute;

它适用于局部变量,但它对属性失败并出现以下错误:

错误 CS1061:类型 System.Collections.Generic.Dictionary&lt;string,System.Collections.Generic.Dictionary&lt;string,UnityEngine.Vector2[]&gt;&gt;' does not contain a definition foradd' 并且找不到扩展方法 add' of typeSystem.Collections.Generic.Dictionary>'(您是否缺少 using 指令或程序集引用?) (CS1061) (Assembly-夏普)

【问题讨论】:

    标签: c# arrays generics dictionary


    【解决方案1】:

    您必须使用Add 而不是add。 C# 区分大小写。

    【讨论】:

    • 啊,愚蠢的错误,谢谢。我不习惯使用大写字母的方法名称:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多