我看到有人用這種語法get訪問的一類如何使用C#=>操作員返回值get訪問
public int _f;
public int f
{
get => _f;
}
,而不是
public int _f;
public int f
{
get {return _f;}
}
的C#源代碼
和我想知道做C#有=>運算符用於簡化
{return x;}
到
=> x;
如果是這是什麼要求?哪個c#版本和哪些命名空間應該使用?
感謝
我檢查了文檔,你說得對,但是問題是我不能以任何方式編譯這段代碼! 現在我安裝了Visual Studio 2015更新3,我的項目是針對.net 4.6,但是當我編譯該類時它失敗get => ...部分 它說明我在這裏清除了錯誤 對C#6的所有要求,但沒有成功 http://stackoverflow.com/questions/23605210/what-clr-is-needed-for-c-sharp-6 –
嗯,我不知道你的問題實際上是什麼。我可以編譯這段代碼而不會出現任何錯誤。 – bakala12