c# - Pass code to a method as an argument -
i have list of methods pretty same thing, except few differences:
void dowork(string parameter1, string parameter2) { //common code ... //custom code ... //common code ... } i want streamline solution reusing common code passing custom code method.
i assume have use action parameters accomplish this, can't figure out how.
the other answers great, may need return custom code, need use func instead.
void something(int p1, int p2, func<string, int> fn) { var num = p1 + p2 + fn("whatever"); // . . . } call this:
something(1,2, x => { ...; return 1; }); or:
int myfunc(string x) { return 1; } something(1,2 myfunc);
Comments
Post a Comment