I’m using lambdas quite a bit in a library. One thing that really irks me is I can’t seem to get rid of the return statement and I have have quite a bit of boiler-plate type code around them.
This is how it works so far:
public delegate IBarelyView HandlerInvoker(IDictionary<string, string> route, IDictionary<string, string> form);
public void MyFunc(string foo, HandlerInvoker invoker) { }
This is the code I have worker to use MyFunc:
MyFunc("foobar", (x, y) => { return new Xyz();});
Now I know this isn’t too bad. However, I’d really like to be able to use the Linq type syntax. For instance, it’s easy enough to do
ObjectList.Where(x=>x.Foo=="bar");
As you can see, positives for the Linq syntax is no return statement, no parentheses around the “arguments”, and no curly braces.
Why can’t I have this kind of syntax in my lambdas? If I remove the return statement I get an error about not all code paths returning a value.
Try:
MyFunc("foobar", (x, y) => new Xyz());