which version of the code below is right?
- by TheVillageIdiot
Hi I found this function in a utilities code file:
Version 1:
public static bool IsValidLong(string strLong)
{
bool result = true;
try
{
long tmp = long.Parse(strLong);
}
catch (Exception ex)
{
result = false;
}
return result;
}
I want to replace this (and validators for other types) with following:
Version 2:
public static bool IsValidLong(string strLong)
{
long l;
return long.TryParse(strLong, out l);
}
which version is better and why?