Reputation: 5627
New to C#, and I'm reviewing some code that has the following return statement:
return (Object) null
What does this mean in C#, what will be returned ?
Thanks
Upvotes: 3
Views: 1049
Reputation: 50114
The only place I can think of where this is required is in an anonymous method where the compiler can't infer the return type.
For example,
var boxedThings = strings.Select(s =>
{
int i;
if (int.TryParse(s, out i))
return i;
double d;
if (double.TryParse(s, out d))
return d;
return (object)null;
});
doesn't compile without the (object)
.
Upvotes: 11