double.TryParse()和double.Parse()的比较

一、double.TryParse("1234,34,49",out temp)
这个方法用来查看字符串"1234,34,49"是不是能够转成一个double类型的数字,如果能转换成功则函数返回值为true,且用out temp来保存这个转换后的double,如果不能转换则false,temp保持原来的值不变.

差别就在于Parse和TryParse之中转换不匹配时,是否抛出错误. 他们之中核心的转换方法是一样的,区别大概如下:
double Parse(string value){
    try{
        if(转换失败){
            throw new FormatException(...);
       }
    }
    catch(FormatException){
    //其他判断...
    //返回其他值,或者throw;
    }
    return Nan;
}

bool TryParse(string value,out double result){
    if(转换失败){
      return false;
    }
    return true;

二、因为await 只能wait Task,并且await 只能用在async 标记的方法中,async 关键字表明这是个异步方法。

 

原文地址:https://www.cnblogs.com/experience/p/4442682.html