Answers for "Generic parsing from string"

0

Generic parsing from string

private static void GetInput<T>(string prompt, ref T Input)
 {
 bool isValid = false;
 while (!isValid)
 {
 try
 {
 Console.Write(prompt);
string sInput = Console.ReadLine();
 Input = (T)Convert.ChangeType(sInput, typeof(T));
 isValid = true;
 }
 catch
 {
 isValid = false;
 }
 }
 }
Posted by: Guest on March-24-2022

Browse Popular Code Answers by Language