I have a list with methods

List<Action<object>> methods_1 = new List<Action<object>>(); methods_1.Add(delete); methods_1.Add(upload); methods_1.Add(open); 

How to call this or that method from this list?

  • By index methods_1[1].Invoke() , but packing methods into a collection is a strange practice. There are delegates. - Bulson
  • But to be honest, what you are doing is, so to say, so-so. You need to change something drastically. Why do you need a list of methods? - Vadim Ovchinnikov
  • @VadimOvchinnikov I shouldn’t work wonders, I just learn this language and try to practice it differently - ZOOM SMASH
  • @ZOOMSMASH I personally do not criticize you, I criticize your approach. Please answer about the purpose of this list, and I will try to help you. By the way, if I didn’t want to help you, I would just give the answer and that's it. - Vadim Ovchinnikov
  • @VadimOvchinnikov the essence of the program is as follows: a goal is selected, a command is entered into the textbox, which calls a method from a list of methods, which is different for each goal. I hope clearly explained, something like a mini console - ZOOM SMASH

1 answer 1

If these methods are visible, then simply by name: delete(); , upload(); , open(); .

You can simply by index: var obj = /* какой-то объект */; methods_1[1](obj); var obj = /* какой-то объект */; methods_1[1](obj);