C#语法糖——持续更新

C# 语法糖——持续更新

1. return的switch写法
public string ReturnMethod(int x)
{
    return x switch
    {
        2 => "2",
        3 => "3",
        _ => "default" //_ 代表switch中的default
    };
}
2. 消除不使用await关键字时的编译器警告

如下图:

C#语法糖——持续更新

在方法前增加_=即可消除编译器警告

_=WaitSomething();

如下图所示:

C#语法糖——持续更新