No. However, if you first declare the method as a lambda, you can set it, although I would try to do it during initialization.
class MyClass {
public MyClass(Action<int> myMethod)
{
this.MyMethod = myMethod ?? x => { };
}
public readonly Action<int> MyMethod;
}
However, this cannot implement the interface declared by MyMethod, unless the interface specifies a lambda property.
F # has object expressions that allow you to compose an object from lambda. Hopefully at some point this is part of C #.
source
share