1

我在将具有 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<string,System.Collections.Generic.Dictionary<string,UnityEngine.Vector2[]>>' does not contain a definition foradd' 并且找不到扩展方法add' of typeSystem.Collections.Generic.Dictionary>'(您是否缺少 using 指令或程序集引用?)(CS1061)(Assembly-CSharp)

4

1 回答 1

1

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

于 2013-03-25T11:13:11.063 回答