c# 7.0 學習筆記

refer : https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7

 

out 可以寫在裡面了

// int result = 0; 不需要寫在外面了 
if
(!int.TryParse(input, out int result)) { return null; } return result;

 

Local functions, 終於有了, 寫習慣 js 的我超愛 

[Route("")]
public async Task<IActionResult> Index()
{
    string abc = dada();
    string dada()
    {
        return "a";
    }
}

 

getter setter 

// Expression-bodied constructor
public ExpressionMembersExample(string label) => this.Label = label;

// Expression-bodied finalizer
~ExpressionMembersExample() => Console.Error.WriteLine("Finalized!");

private string label;

// Expression-bodied get / set accessors.
public string Label
{
    get => label;
    set => this.label = value ?? "Default label";
}

 

關鍵詞:label nbsp gt string expression public bodied int result c#

相關推薦:

C# Features: Innovations or Imitations? – Part 3

Decompiling Syntactic Sugar in C#

C#7.0新特性(VS2017可用)

C# 語言特性發展史

C# 7.x Features

C# 語言歷史版本特性(C# 1.0到C# 8.0彙總)

C# 7.1, 7.2 and 7.3 - New Features (Updated)

New in C# 7.0: Part 4 – Expression-Bodied Members

C#7.0新特性