我有一个非常简单的类,由于构造函数中的默认参数而无法编译。语言为 C#,该类将用于 Unity3d 游戏。所以这个编译错误发生在 Unity 的“IDE”中
编译错误:
Assets/Utilities/GenericClasses.cs(30,94):错误 CS1736:分配给可选参数“nName”的表达式必须是常量或默认值
public class Element {
public static readonly string NULL_NAME = "___NULL_NAME___";
public enum elementType {E_ELEMENT, E_MODEL, E_VIEW, E_SUPER, E_ARC};
private string name;
private elementType type;
// line 30 is below
public Element(elementType nType=elementType.E_ELEMENT, string nName=NULL_NAME) {
type = nType;
name = nName;
}
}
我究竟做错了什么?