Hallo zusammen
Ich bin neu hier und hab gleich ne Frage xD.
Ich würde gerne eine Funktion schreiben, welche mir mit return eine Funktion startet.
Die Idee dahinter ist folgende: ich will in eine Consolenapplication einen Befehl eingeben. Dieser Befehl soll mit einem Array verglichen werden, in welchem alle Befehle gelistet sind. Stimmt der Befehl überein, soll die gleichnamige Funktion geöffnet werden.
Ich dachte mir es wäre am einfachsten, den Befehl mit (); zurück zu geben. Leider funktioniert das nicht.
So habe ich mir das gedacht...(geht aber nicht)
=====================Schnipp===================================================
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
| using System;
namespace funktionstest { class Program { public static void functionA() { Console.WriteLine("functionA is started"); } public static void functionB() { Console.WriteLine("functionB is started"); } public static void functionC() { Console.WriteLine("functionC is started"); } static String func(string command) { string[] allCommands = new string[] { "functionA", "functionB", "functionC"}; int length = allCommands.Length; bool valid = false; for(int a=0; a<length; a++) { if(command == allCommands[a]) { valid = true; command = command + "();"; return command; } } return "default"; } public static void Main(string[] args) { String command; Console.Write("Insert command: "); command = Console.ReadLine(); func(command); Console.Write("Press any key to continue . . ."); command = Console.ReadLine(); } } } |
===================schnapp============================================================
Ich hoffe ihr könnt mir helfen. Danke schon im voraus.
Pfammi