c# - Is there a difference between return myVar vs. return (myVar)? -


I was looking at some example C # code, and found that the returns of () in an example are wrapped.

I've always done this:

return myRV;

Does it matter:

  return (myRV);  

update: this was the question. Thanks for the fun question!

In practice, there is no difference.

Principle can be a difference. There are three interesting points in the C # specification, where it can present a difference

First of all, consider the following for the conversion type of anonymous activities and handing over the expression tree:

< Pre> function & lt; Int & gt; F1 () {returns () = & gt; 1; } Fx & lt; Int & gt; F2 () {return (= = 1);}

F1 is clearly legal. What is F2 ? Technically, no section 6.5 says that a lambda expression has a conversion for a corresponding representative type. Is this lambda expression ? No. This is a bracket expression in which there is an lambda expression .

The Visual C # compiler violates a small device here and your login

Second:

  int m () {return1;} fx  f3 () {return m ;} Fx  F4 () {return (m);}  

F3 is legal. What F4 is? No. Section 7.5.3 states that a bracket expression can not contain any method group. Then, for your convenience, we violate the specification and allow the conversion.

< P> Third:

  enum e {none} ef5 () {return 0;} e f6 () {r Turn (0);}  

F5 is legal. What is F6 ? No. The technique states that any enumerated type of conversion is done by literally zero. " (0) " is not literal zero, it is a bracket followed by verb rather than zero, after which we violate the specification here and in fact any time For constant expression align as zero , and not just literal zero.

So in every case, we allow you to run with it, even if technically it is illegal to do this


Comments