c# – How to read an int variable if it's an string
If you just want to read a string, try to convert to an integer, and exit the program if it’s not a valid integer, then you’d use int.TryParse, like this: string input = Console.ReadLine(); if (int.TryParse(input, out x)) { // do something with x } else { // input was invalid. } If you want … Read more