C#7.0中的表达式强健的获取/设置访问器功能 [英] Expression bodied get / set accessors feature in c# 7.0

查看:188
本文介绍了C#7.0中的表达式强健的获取/设置访问器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个班级中有这段代码

I'm having this code in a class

private string test;
public string Test
{
    get =>  test;
    set => test = value;
}

但是编译器不允许我编译。它说

But the compiler won't let me compile. It says

CS1043 { or ; expected 
CS1513 } expected

我使用的是VS 2017,目标是.NET FW 4.6一个MVC 5项目

I'm using VS 2017 and targeting .NET FW 4.6 with a MVC 5 Project

有人知道为什么它不起作用吗?

Any idea why it isn't working?

推荐答案

您必须在项目中将编译器设置为版本7。

You have to set the compiler to version 7 in your project.

项目属性→(选项卡)生成→高级→语言版本= C#7.0

Project properties → (tab) Build → Advanced → Language version = C# 7.0

通过@gsharp

还要检查您对.NET编译器平台的(NuGet)参考 Microsoft .Net.Compilers

check also your (NuGet) reference to the .NET Compiler platform Microsoft.Net.Compilers.

这篇关于C#7.0中的表达式强健的获取/设置访问器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆