是否使用左右返回值括号提供任何编译器相关的福利?编译器、括号、返回值、福利

2023-09-03 01:27:20 作者:该用戶已成仙

只是看一个相当伟大的微软讲师,迈克Taulty 的视频。在他的录像,他始终如一地包围了他的返回值与括号,即使单个值:

 收益率(空);
 

有一些隐藏的利益与智能感知,或者一些与编译器,这一规定?

低于code:

 公开的ObservableCollection< MailViewModel>电子邮件
{
  得到
  {
    返回(电子邮件);
  }
  组
  {
    电子邮件=价值;
  }
}
 

解决方案

当然是有性能差异,因为这两种形式转化到相同的IL 。运行时无法判断,即使它想。您可以使用反射或ILDASM或any其他反编译来查看生成的IL。

没有智能感知的利益或损害。

在语义也完全相同。

我将不讨论它是否是最好的风格或不是因为讨论不属于堆栈溢出。这也是个人的喜好问题。

c 中的if后的括号里的数字的取值范围是不是int的取值范围,有没有增加if后的括号里的数字取值范围的方法

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;
  }
}

解决方案

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.

 
精彩推荐
图片推荐