Tell me please what is different between
return null;
and
return (null);
Sometime i'd seen each an examples
Tell me please what is different between
return null;
and
return (null);
Sometime i'd seen each an examples
There's no difference in behaviour whatsoever - but the latter is distinctly unidiomatic. I've previously seen it as a sign that the author seems to think that return
is a function call, or at least want to treat it as such. (Sometimes there are brackets around every return value.)
Just use the first version.
The parenthesis serve no purpose.
Those two statements are exactly the same when you look to the actual IL code generated.
According to the specs, the ()
operator serve two purposes:
Specify casts, or type conversions, like
(int)4M;
Invoke methods or delegates, like
Method();
Parenthesis are also used to indicate (a group of) conditions conditions, like:
if (a && (b || c))
Or:
switch (a)
Or to specify the operator precedence (deviating from the default):
(a + b) * c
Lamdba expressions:
(x) => { }
Etc, etc.
Your code is neither of them, so they are useless.
It's the same difference as between
var a = (new A());
and
var a = new A();
namely, no differene at all. The parenthesis is redundant and should be omitted. Some feel it makes the code more coherent with method calls, however the return
statement is not a function call.