What is idiomatic code?

后端 未结 5 930
时光说笑
时光说笑 2020-12-07 14:22

I\'d be interested in some before-and-after c# examples, some non-idiomatic vs idiomatic examples. Non-c# examples would be fine as well if they get the idea across. Thanks.

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 15:06

    In PHP I sometimes encounter code like:

    foreach ($array as $value) {
        $trimmed[] = trim($value);
    }
    return $trimmed;
    

    Which idiomatically can be implemented with:

    return array_map('trim', $array);
    

提交回复
热议问题