Is there a better way to express a parameterless lambda than () =>?

后端 未结 4 1079
我寻月下人不归
我寻月下人不归 2020-12-02 17:04

The () seems silly. is there a better way?

For example:

ExternalId.IfNotNullDo(() => ExternalId = ExternalId.Trim());

4条回答
  •  清歌不尽
    2020-12-02 17:41

    For a lambda, no: you need () =>

    Is it for a delegate or an expression? For delegates, another option is delegate {...}. This may or may not be desirable, depending on the scenario. It is more keys, certainly...

    In some cases (not this one) you can use a target method directly - i.e.

    ExternalId.IfNotNullDo(SomeMethod);
    

提交回复
热议问题