public class x : y
{
public Func<user, bool> SendStuffAction = SendStuff;
//overridden from y
public override bool SendStuff(user u)
{
//do stuff
}
}
Taking the above code, where SendStuff is an local overridden instance method, I get a context error that SendStuff not being static. Can't a delegate point to an instance method from inside the same class to which the method SendStuff exists?
Error is:cannot access static method in a non-static context
What if the method is private, why would it not work then.
private Func<user, bool> SendStuffAction = SendStuff;
Yes, it can...but, you need to set it in the constructor if you do not declare as static.
class MyClass
{
public Func<loan, user, bool> SendStuffAction ;
MyClass()
{
SendStuffAction = SendStuff;
}
bool SendStuff(loan loanVar, user userVar)
{
return true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With