Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

c# - Does using parentheses around return values provide any compiler-related benefits?

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;
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...