// ***************** Use of generics to let the user choose from the 3 Enum variations *********************** static T ChooseVariation <T>() { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Choose {0}", typeof(T).Name); Console.ForegroundColor = ConsoleColor.White; //Using an Array for flexibility Array items = Enum.GetValues(typeof(T)); int counter = 0; foreach (var item in items) { Console.WriteLine("{0} --> {1}", ++counter, item); } //let the user choose a number for the menu int number = UserInput.AskNumber(); //Parse the generic Enum type T choice = (T)Enum.Parse(typeof(T), number.ToString()); // return user choice return(choice); }
public static void SortingMenu() { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("How do you want to see you items sorted?"); Console.WriteLine("1: Quick Sort"); Console.WriteLine("2: Bubble Sort"); Console.WriteLine("3: Bucket Sort"); Console.WriteLine("Any other number: Bubble Sort"); Console.ForegroundColor = ConsoleColor.White; int algorithmChoice = UserInput.AskNumber(); if (algorithmChoice == 1 || algorithmChoice == 3) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("What do you want to see you items sorted by?"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("1: Color Ascending"); Console.WriteLine("2: Color Descending"); Console.WriteLine("3: Fabric Ascending"); Console.WriteLine("4: Fabric Descending"); Console.WriteLine("5: Size Ascending"); Console.WriteLine("6: Size Descending"); Console.WriteLine("Any other number: Color Ascending"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; } else { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("How do you want to see you items sorted by?"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("1: Color Ascending"); Console.WriteLine("2: Color Descending"); Console.WriteLine("3: Fabric Ascending"); Console.WriteLine("4: Fabric Descending"); Console.WriteLine("5: Size Ascending"); Console.WriteLine("6: Size Descending"); Console.WriteLine("7: Size-Color-Fablic Ascending"); Console.WriteLine("8: Size-Color-Fablic Descending"); Console.WriteLine("Any other number: Color Ascending"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; } int variationChoice = UserInput.AskNumber(); Console.WriteLine(); UserChoice(algorithmChoice, variationChoice); }
//========================= Choose payment (non-enum choices) ============================== static PaymentMethod ChoosePaymentMethod() { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Choose payment Method"); Console.ForegroundColor = ConsoleColor.White; //Use of Array for flexibility. Array paymentMethods = Enum.GetValues(typeof(PaymentMethod)); int counter = 0; foreach (var paymentMethod in paymentMethods) { Console.WriteLine("{0} -{1}", ++counter, paymentMethod); } //let the user choose a number for the menu int number = UserInput.AskNumber(); PaymentMethod userPaymentMethod = (PaymentMethod)number; return(userPaymentMethod); }