Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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;
  }
}
like image 958
Fred Lackey Avatar asked Dec 02 '13 16:12

Fred Lackey


People also ask

Does return need parentheses Java?

Like in math, anything inside parenthesis gets handled first. So for a simple return statement they are not needed.

What are the uses of parentheses in Java?

{} are used to define a dictionary in a "list" called a literal parentheses in java: Parentheses are used for two purposes: (1) to control the order of operations in an expression, and (2) to supply parameters to a constructor or method. ................. and many more in simple: A parenthesis is a punctuation mark ...

Are parentheses?

A parenthesis is a punctuation mark used to enclose information, similar to a bracket. The open parenthesis, which looks like (, is used to begin parenthetical text. The close parenthesis, ), denotes the end of parenthetical text. The plural of parenthesis is parentheses.


2 Answers

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.

like image 166
usr Avatar answered Oct 27 '22 00:10

usr


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.

like image 23
Brian Rasmussen Avatar answered Oct 27 '22 00:10

Brian Rasmussen