我在将具有 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 for
add' 并且找不到扩展方法add' of type
System.Collections.Generic.Dictionary>'(您是否缺少 using 指令或程序集引用?)(CS1061)(Assembly-CSharp)