0

It is possible to do something like this on C#? I want a generic void for calling differents methods from another class.

public class custom{ public void A(){} public void B(){} } void doSomething(List<custom> laux, method m ){ foreach(var aux in laux){ aux.m; //something like this } } void main(){ doSomething(new List<custom>(),A); doSomething(new List<custom>(),B); } 
2

1 Answer 1

8

You can do something close to this via an Action delegate:

void doSomething(List<custom> laux, Action<custom> m ){ foreach(var aux in laux){ m(aux); } } void main(){ doSomething(new List<custom>(),c=> c.A()); doSomething(new List<custom>(),c=> c.B()); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.