Boolean types

前端 未结 10 2031
时光说笑
时光说笑 2021-01-22 11:54

During code review I discovered many places of our C# code that looks like this:

if(IsValid()) {
     return true;
}
else {
     return false;
}
<
10条回答
  •  悲哀的现实
    2021-01-22 12:22

    The reasons for the first two examples are entirely human:

    • ignorance
    • lack of intellectual involvement with one's code
    • code was refactored, but only half-way

    There's no reason not to (I know it's a double negative) go with return IsValid();

提交回复
热议问题