I have been writing C# code for 10 years, but I am woefully weak on knowing exactly when to use an interface vs. using a Func or Action. It seems to me that in many places where a method on an interface is called, a Func or Action would work just as well. So, I guess my question is this. If I have an interface with just a single method, or perhaps a couple methods, is there any disadvantage to using a Func or Action instead? Using a Func or Action seems cleaner to me.
Thanks very much.
I guess you can compare an
ActionorFuncwith an interface containing one method, with the difference that you can supply anyActionorFuncthat meets the parameter / return value requirements, where when using interfaces, the supplied object must implement that interface.Perhaps you could call
ActionandFunc“anonymous single method interfaces”.If you look at the design perspective though, your class model would be a drawing of blocks without any lines between them.