是否使用左右返回值括号提供任何编译器相关的福利? [英] Does using parentheses around return values provide any compiler-related benefits?

查看:126
本文介绍了是否使用左右返回值括号提供任何编译器相关的福利?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 收益率(空);
 

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

低于code:

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

解决方案

当然是有性能差异,因为这两种形式转化到相同的IL 。运行时无法判断,即使它想。您可以使用反射或ILDASM或<一href="https://www.google.com/webhp?complete=1&hl=en#complete=1&hl=en&q=free%20.net%20decompiler">any其他反编译来查看生成的IL。

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

语义也完全相同。

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

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.

这篇关于是否使用左右返回值括号提供任何编译器相关的福利?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆