This is an interesting old question. I add the answer because no one noticed a couple of things with the original question.
Which is faster: Convert.ToDouble or Double.TryParse? Which is safer: Convert.ToDouble or Double.TryParse?
I am going to answer both of these questions (I will update the answer later), but first:
For security, what every programmer missed in this question, this is the line (my selection):
It adds only data, which are digits with several digits (1000 1000.2 1000.34 - comma - this is a separator in Russian standards ).
Following this code example:
Convert.ToDouble(regionData, CultureInfo.CurrentCulture);
Interestingly, if the spreadsheets are in Russian format, but Excel incorrectly typed the cell fields, then what is the correct interpretation of the values ββcoming from Excel?
Here is another interesting thing about two examples regarding speed:
catch (InvalidCastException) { // is not a number }
This will probably generate an MSIL that looks like this:
catch [mscorlib]System.InvalidCastException { IL_0023: stloc.0 IL_0024: nop IL_0025: ldloc.0 IL_0026: nop IL_002b: nop IL_002c: nop IL_002d: leave.s IL_002f } // end handler IL_002f: nop IL_0030: return
In this sense, we can probably compare the total number of MSIL instructions executed by each program - more on this later when I update this post.
I believe that the code should be correct, clear and fast ... In that order!
John Zabroski Dec 04 '18 at 0:01 2018-12-04 00:01
source share