Int32 result = -1;
if (Int32.TryParse("210s"out result))
{
    
// Parsing succeeds, now you can safely use the value.
}
else
{
    
// Parsing fails, this route is faster.
}

Int32 result = -1;
try
{
    result 
= Int32.Parse("210s")
}
catch(Exception)
{
    
// Parsing fails, this route is slower.
}

posted on 2008-12-23 14:46  茹古涵今  阅读(307)  评论(0编辑  收藏  举报