Does using parentheses around return values provid

2020-02-13 09:31发布

Was just watching a video of a rather great Microsoft instructor, Mike Taulty. In his videos he consistently surrounded his return values with parentheses, even single values:

return (null);

Is there some hidden benefit with IntelliSense, or maybe something with the compiler, that this provides?

Code below:

public ObservableCollection<MailViewModel> Emails
{
  get
  {  
    return (emails);
  }
  set
  {
    emails = value;
  }
}

标签: c# .net
2条回答
家丑人穷心不美
2楼-- · 2020-02-13 10:01

There is certainly no performance difference because both forms translate to the same IL. The runtime couldn't tell even if it wanted. You can use Reflector or ILdasm or any other decompiler to look at the generated IL.

There is no intellisense benefit or detriment.

The semantics are also exactly identical.

I will not discuss whether it is better style or not because that discussion does not belong on Stack Overflow. It is also a matter of personal taste.

查看更多
Evening l夕情丶
3楼-- · 2020-02-13 10:12

There's no benefit wrt the code generated. You can verify this by looking at the IL generated. As for whether it improves readability or not, that is subjective.

查看更多
登录 后发表回答