I have a base class, whose ctor takes a delegate as a parameter and a class which inherits from it.
The following works just fine:
class Base
{
public Base(Func<bool> func)
{
}
}
class Sub : Base
{
public Sub()
: base(() => true)
{
}
public Sub(int i)
: base(() => { return true; })
{
}
}
How can I pass an instance function as a parameter? Compiler complains with error "An object reference is required for the non-static field, method, or property".
What I would like to have is this:
class Sub : Base
{
public Sub()
: base(Func)
{
}
private bool Func()
{
return true;
}
}
It would work if Func was a static method. But I'd like to use instance members inside the function.
How could I accomplish this?