其他分享
首页 > 其他分享> > switch语法

switch语法

作者:互联网

一般使用

return a switch
{
    100 => 10,
    _ => 99,
};
return tag switch
{
    TagEnum.First => 1,
    TagEnum.Two => 2,
    TagEnum.Three => 3,
    _ => 0
};

使用属性

return tagObject switch
{
    { Tag1: TagEnum.First } => 1,
    { Tag1: TagEnum.Two } => 2,
    { Tag1: TagEnum.Three } => 3,
    _ => 0
};

使用位置

return tagObject switch
{
    var (x, y) when x == TagEnum.First && y == TagEnum.Two
        => 3,
    _ => 0
};

示例代码

SwitchTestDemo

标签:return,Tag1,Two,语法,switch,TagEnum,First
来源: https://www.cnblogs.com/Lulus/p/15977922.html