I have the following code.
using System;
class program
{
static void Main()
{
string StrNumber = "100TG";
int result = 0;
bool IsConversionSuccessful = int.TryParse(StrNumber, out result);
if (IsConversionSuccessful)
{
Console.WriteLine(result);
}
else
{
Console.WriteLine("Invalid");
}
}
}
I know that TryParse method tries to convert StrNumber(100TG) into an integer.
And if it succeeds, it's going to save converted value into a result variable and return true for boolean. And if it fails, a result value will remain as 0 and it will return false for boolean.
My question is that no matter what kind of boolean value IsConversionSuccessful variable gets, wouldn't "if(IsConversionSuccessful)" get activated? Am I misunderstanding TryParse Method?