Double.TryParse or Convert.ToDouble - which is faster and safer?

前端 未结 11 984
滥情空心
滥情空心 2020-11-28 07:28

My application reads an Excel file using VSTO and adds the read data to a StringDictionary. It adds only data that are numbers with a few digits (1000 1000,2 10

11条回答
  •  一生所求
    2020-11-28 07:41

    To start with, I'd use double.Parse rather than Convert.ToDouble in the first place.

    As to whether you should use Parse or TryParse: can you proceed if there's bad input data, or is that a really exceptional condition? If it's exceptional, use Parse and let it blow up if the input is bad. If it's expected and can be cleanly handled, use TryParse.

提交回复
热议问题