C# switch in lambda expression

后端 未结 6 924
夕颜
夕颜 2021-02-04 04:04

Is it possible to have a switch in a lambda expression? If not, why? Resharper displays it as an error.

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 04:58

    Hmm, I see no reason why this shouldn't work. Just be careful with the syntax you use

    param => {
        // Nearly any code!
    }
    
    delegate (param) {
        // Nearly any code!
    }
    
    param => JustASingleExpression (No switches)
    

提交回复
热议问题