3 ms·
You're right, I'm a bit rusty, not having written anything large in C# for a couple of years. The compiler can't infer the type, so it would be: Func<strin
by nkohari 14y ago
You're right, I'm a bit rusty, not having written anything large in C# for a couple of years. The compiler can't infer the type, so it would be:
Func<string> foo = () => "foo";
func()
I'm well aware of the difference between an anonymous function and an expression in C#. What in your example suggests that you should be using an expression? In practice, you never need to work with expression trees unless you're doing metaprogramming of some kind. They were added to the framework primarily to support metaprogramming and support the DLR.
LINQ (or at least "LINQ to Objects") does not use expression trees. For example, this is the signature of the Select() extension method:
public static IEnumerable<TResult> Select<TSource, TResult> (this IEnumerable<TSource> source, Func<TSource, TResult> selector) { ... }
Note the lack of Expression<Func<>>.
Things like LINQ to SQL and the Entity Framework translate these statements into expression trees, but they do it transparently inside the framework.
My point in bringing up Java is that in order to do something like what we're talking about, you'd have to jump through a whole bunch of hoops. It certainly would be more difficult than in C# -- which is really what matters more than the "purity" of the language.