With the .NET Framework 2.0, there is a great number of improvements to the Base Class Library, one big improvement is that when you want to parse a string input into any other primitive value type(except Enum), you can use the TryParse instead of Parse method, the reason is that TryParse method won't throw an exception if the conversion fails just as the following code illustrates:
Int result = -1;
if (Int.TryParse("210s", out result))
{
    // Parsing succeeds, now you can safely use the value.
}
else
{
    // Parsing fails, this route is faster.
}
But if you use Parse method, you have to handle the situation when an exception would be thrown.
Int result = -1;
try
{
    result = Int.Parse("210s")
}
catch(Exception)
{
    // Parsing fails, this route is slower.
}
Because throwing an exception and recovering from it is quite expensive, so you can improve your application's performance a lot by reducing the happening of exception as many times as possible.
翻译
.Net Framework 2.0 对基础类库进行了大幅改进,你可以使用 TryParse 对字符串进行类型转换,成功返回 true,失败则返回 false。
例如
Int result = -1;
if (Int.TryParse("210s", out result))
{
    // Parsing succeeds, now you can safely use the value.
}
else
{
    // Parsing fails, this route is faster.
}
如果使用 Parse 方法的话,你需要进行异常处理。
Int result = -1;
try
{
    result = Int.Parse("210s")
}
catch(Exception)
{
    // Parsing fails, this route is slower.
}
由于处理异常的代价昂贵,所以使用 TryParse 替代 Parse 可以大幅提升系统运行效率。
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号