You want to say
this(t => { })
Think of it this way. You need t => anonymous-expression-body . In this case, anonymous-expression-body is expression or block . You cannot have an empty expression, so you cannot specify an empty method body with expression . Therefore, you need to use block , in which case you can say { } to indicate that a block has an empty statement-list and therefore is an empty body.
For more information, see the grammar description, Appendix B.
And here is another way to think about it that you can use to discover it for yourself. Action<T> is a method that takes T and returns void . You can define an Action<T> using a non-anonymous method or an anonymous method. You are trying to figure out how to do this using an anonymous method (or rather a special anonymous method, namely a lambda expression). If you want to do this using a non-anonymous method, you will say
private void MyAction<T>(T t) { }
and then you can say
this(MyAction)
which uses the concept of a group of methods. But now you want to translate this into a lambda expression. So, letβs just take the body of the method and make it a lambda expression. Therefore, we throw away private void MyAction<T>(T t) and replace it with t => and literally copy the body of the method { } .
this(t => { })
Boom.
jason
source share