模式匹配
public static int Match(int num)
{
    return num switch
    { 
        > 5 => 0,
        < 5 => 2,
        5 => 3
    };
}


编辑器会根据情况生成最优的if else或则是switch


首页 我的博客
粤ICP备17103704号