Sometimes you can use a Dictionary of Actions to map strings to methods:. Without more details of what you're trying to do, a basic alternative could be to have one method and use a switch statement.
If you want to Defuse - Interstate / Krack a method by name, getting the name from a string, you'll have to use Women And Gold - Spooky Tooth - The Mirror. However, I would not do this using input from the user, this is like an SQL injection attack, only much worse.
This code will work for all methods may be your input is not correct or you want to execute multiple methods. Learn more. How to run a string method? Ask Question. Asked 6 years, 9 months ago. Active 6 years, 9 months ago. Viewed times. Is there another way to do this? Why it is not working when you have a lot of methods? What is the problem? You can write something like this. Sometimes you can use a Dictionary of Actions to map strings to methods: using System; using Distant Strings - Cool Hand Flex - Distant Strings / Gotta Get Going.
Split ' ' ; if! Do error handling. Matthew Watson Matthew Watson What you want to Distant Strings - Cool Hand Flex - Distant Strings / Gotta Get Going is something like this. Micka Micka 1, 13 13 silver badges 31 31 bronze badges. Well arrays containing functions pointers also exist in C. Split ' ' ; PerformAction s,s. Lasse V. Karlsen Lasse V. Karlsen k 88 88 gold badges silver badges bronze badges. FirstOrDefault ; if action. Pieter Geerkens Pieter Geerkens Parvathy Parvathy 1, 2 2 gold badges 20 20 silver badges 38 38 bronze badges.
The Miracles - Give Me Just Another Day / I Wanna Be With You, Gates Of Eden - Bob Dylan - Bringing It All Back Home, På Bröllop - Björn Ulvaeus & Benny Andersson - Lycka, Makin Love - Kiss - Kings Of The Nighttime 1976-1977, Tommy Roe - Heather Honey / Money Is My Pay