Notice if you have the following code :
string inputData = Console.ReadLine();
int a = Convert.ToInt32(inputData);
if (a % 2 == 0)
{
Console.WriteLine("PAR");
}
Line 3 will give you an error if you type in a non numeric value such as Z.
This will result in a
System.FormatException
Notice that won't happen in the example below. You should note that if
int.TryParse fails to pass the received input from the user, you will not get an exception, and that's because int.TryParse fails silently :
string inputData = Console.ReadLine();
if (int.TryParse(inputData, out int parsed) && parsed % 2 == 0)
{
Console.WriteLine("PAR");
}
You should only use
Convert.ToInt32 if you are sure the user input is in fact numeric. No such verifying of the input being numeric is checked below when blindly converting the input received. So I would avoid writing code like this personally :
string inputData = Console.ReadLine();
int parsed = Convert.ToInt32(inputData);
if (parsed % 2 == 0)
{
Console.WriteLine("PAR");
}
Does this make sense?