C# Hidden Optimizations(gavindraper.co.uk) |
C# Hidden Optimizations(gavindraper.co.uk) |
Java, as far as I know, does not allow if (someObject) where someObject is a class type. AFIAK, java only allows that if someObject is a bool, or possibly an int as well.
In strongly typed languages in general, null is not the same thing as false and not-null is not the same thing as true.
Expression<Func<int, int>> e = (x) => x + 1;
Func<int, int> f = e.Compile();
int b = f.Invoke(42); var f = function(x) { return x + 1; };
var b = f(42); Func<int, int> f = x => x + 1;
int b = f(42);
This is shorter than the JavaScript. The C# is more verbose where has to specify a type for f because it cannot work it out from context (in fact the left side of the '=' supplies type information to the right side), but the actual expression on the right is less verbose than the JavaScript with its "function" and "return" keywords.If you want, the second line can be
var b = f(42);
But it's the same number of chars. I don't think that you gain anything from letting the compiler work out that b is an int. var f = ((x) => x + 1).Compile();
int b = f.Invoke(42);They're also not very hidden either.
It is damned handy though.