C# 中的 Lambda 属性 - "Invalid token in class, struct, or interface member declaration"
Lambda properties in C# - "Invalid token in class, struct, or interface member declaration"
在我的项目中,属性分配如下:
[ConfigurationProperty("message", IsRequired = true)]
public string message=> this["message"] as string;
当我编译代码时出现此错误:
Invalid token '"message"' in class, struct, or interface member
declaration Error 4 Identifier expected
表情型成员were introduced in C# 6.0。您将必须针对该版本进行编译或使用遗留成员语法。
作为解决方法,您可以这样做:
[ConfigurationProperty("message", IsRequired = true)]
public string message {
get {
return this["message"] as string;
}
}
在我的项目中,属性分配如下:
[ConfigurationProperty("message", IsRequired = true)]
public string message=> this["message"] as string;
当我编译代码时出现此错误:
Invalid token '"message"' in class, struct, or interface member declaration Error 4 Identifier expected
表情型成员were introduced in C# 6.0。您将必须针对该版本进行编译或使用遗留成员语法。
作为解决方法,您可以这样做:
[ConfigurationProperty("message", IsRequired = true)]
public string message {
get {
return this["message"] as string;
}
}