Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

C# has switch statements which are C/C++ style switches and switch expressions which are like Rust's match except no control flow statements inside:

    var len = slice switch
    {
        null => 0,
        "Hello" or "World" => 1,
        ['@', ..var tags] => tags.Length,
        ['{', ..var body, '}'] => body.Length,
        _ => slice.Length,
    };
(it supports a lot more patterns but that wouldn't fit)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: