Get the current method to repeat?

Hello. Starting out – grinding ton of console apps. Figured to make a menu – good choice, I'm up to 45-ish small apps now. But I want to make sure to reuse one particular code – the Finalizer.

So, my mighty training program has a menu, where you enter number, then get to correct thing.

string[] menuPicks = new string[] { null, "Number:\t Is even or odd?", "Number:\t Divides by both 5 and 7?", "Number:\t Is third digit - 7?", "Number:\t Is third bit 1 or 0?", "Calc:\t Trapezoid area" } 

It is then displayed

 // Displays the main menu for (int i = 1; i <= menuOptions; i++) { Console.WriteLine(" [" + i + "] \t" + menuPicks[i]); } // Selection Console.Write("\n Your pick, sir? [1 - " + menuOptions + "] :: "); string userPick = Console.ReadLine(); 

and then there is

// Switch statement for initializing methods switch (userPick) { case "39": Console.WriteLine("\n [" + userPick + "] " + menuPicks[int.Parse(userPick)]); Console.WriteLine(" goal: translates integer to string"); Console.WriteLine(" usage: enter digit from 1-999\n"); NumberToWord(); break; } 

After that it just launches the correct public static void thingy.. For testing and other purposes – I use finalizer, which looks like this.

 // Finalizer Console.Write("\n 'r' to try again | 'm' to menu | other keys - quit :: "); string finalGet = Console.ReadLine(); switch (finalGet) { case "r": CardDeck(); break; case "m": MainMenu(); break; default: Console.WriteLine(" Bye!"); Console.ReadKey(); break; } 

All I'm wondering is how to get the finalizer – in one line for each app, and not have to copy this block it in each of 50+ mini-apps, along with changing the function name all the time. Thanks in advance.

by lolsteamroller via /r/csharp

Leave a Reply