yeah sorry - I didn't edit my email before I sent. With a NUMBER it's
nearly the same with a non-number, TryParse is faster.
apologies.
11/16/05, Peter H <peter.hartlen (AT) sib (DOT) sewrote:
Hello Sam!
Not really, I also read the article and it says exactly the opposit. The
performance hit of try-catch is a lot greater than what you get using
Double.TryParse. I'm eager to agree with Brett's statment that
Double.TryParse is definitely created to prevent the exception overhead
when
checking numbers.
the other hand, Visual Basic's IsNumeric function is a simple wrapper
using try-catch itself. This is what I have read and the tests I did
confirms the theory.
Also, John, that link you provided to Int32.TryParse, is for WinFX SDK.
(which I don't really know what it is).
Int32.TryParse is not part of the standard .NET Framework v. 1.1 is it?
__ So how about getting that string to an Integer (not double) __
I used the code inte the article <http://aspalliance.com/80>
http://aspalliance.com/80 and also created a function (that uses
Double.TryParse) to validate the string as an integer AND convert the
resulting double into an integer. The performance hit of the conversion
was
very small, and compared to using try-catch it's a lot faster!
BUT! To my horror I discovered that the use of
double.TryParse(strInputVal,
NumberStyles.Integer,
NumberFormatInfo.CurrentInfo,
out dVal);
Does not return false if the value is above Int32.MaxValue, it seems like
it
simply makes sure strInputVal consists of numbers only (not how many)
could this be true?
/ Peter
--
Message
From: CSharpNET (AT) yahoogroups (DOT) com [mailto:CSharpNET (AT) yahoogroups (DOT) com]
Behalf
Sam Acheson
Sent: Wednesday, November 16, 2005 5:02 PM
To: CSharpNET (AT) yahoogroups (DOT) com
Subject: Re: [C#.NET] RE: TryParse vs. Exception
--
If you're familiar with VB6, it's similar to the IsNumeric function. It
checks if a value is numeric before it attempts the cast, but has the
additional functionality of returning the double (final parameter) if the
cast is valid.
I found this article by googling Double.TryParse benchmark.
http://aspalliance.com/80
It seems that it is little more than wrapped Try{}Catch{} block, as the
performance was nearly the same. My guess is it's a helper function that
will allow more concise code.
What's interesting to me is the incremental char method.
11/16/05, Peter B <peter.hartlen (AT) sib (DOT) sewrote:
In CSharpNET (AT) yahoogroups (DOT) com, "Matt Evans" < matt@twrote:
Also one other thing to consider is what the TryParse function
actuall does (I don't know this myself) but it could use exceptions
internally, and just return false if it catches one
Exactly!
That's why I am hoping someone knows this for a fact.
/ Peter
>
>
>
>
>
>
>
Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
[Non-text portions of this message have been removed]
>
>
>
>
SPNSRED LINKS
Programming
<
languages North
<
&america C
<
programming language
Computer
<
programming
languages
YAH! GRUPS LINKS
>
>
>
* Visit your group "CSharpNET
<" on the web.
--
* To unsubscribe from this group, send an email to:
CSharpNET-unsubscribe (AT) yahoogroups (DOT) com
<mailto:CSharpNET-unsubscribe@>
--
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<.
--
>
>
>
>
[Non-text portions of this message have been removed]
>
>
>
>
>
Yahoo! Groups Links
>
>
>
>
>
>
>
[Non-text portions of this message have been removed]
Yahoo! Groups Sponsor
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
Yahoo! Groups Links
<*To visit your group on the web, go to:
<*To unsubscribe from this group, send an email to:
CSharpNET-unsubscribe (AT) yahoogroups (DOT) com
<*Your use of Yahoo! Groups is subject to: