Article View: borland.public.csharpbuilder.language.csharp
Article #464Re: Where are StrToXXXDef and TryStrToXXX?
From: Lee Grissom
Date: Wed, 08 Dec 2004 20:43
Date: Wed, 08 Dec 2004 20:43
22 lines
1708 bytes
1708 bytes
Eric wrote:
> There's a TryParse method on the double type, and in v2.0 of the
> Framework it will be added to all the types. This is good because it
> avoids throwing an exception if the conversion fails.
Precisely, so I strongly recommend you use Double.TryParse now (yes even for
int types). It's much more efficient than using the exception mechanism.
// TODO: .NET 2.0 will introduce Int32.Parse so change this later.
double myNum = 0.0;
bool isNum = Double.TryParse( inputNum, NumberStyles.Integer,
NumberFormatInfo.InvariantInfo, out myNum );
if (isNum)
{
someInteger += (int) myNum;
}
else
{
...
}
--
Lee
Technical Details
Message-ID:
<41b76754$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4174fd87@newsgroups.borland.com> <417526d7@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,11f13a69b08b4c7a X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Lee Grissom" <Lee.Grissom@REMOVETHISquest.com> Newsgroups: borland.public.csharpbuilder.language.csharp References: <4174fd87@newsgroups.borland.com> <417526d7@newsgroups.borland.com> Subject: Re: Where are StrToXXXDef and TryStrToXXX? Date: Wed, 8 Dec 2004 12:43:02 -0800 Lines: 24 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 12.173.168.195 Message-ID: <41b76754$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1102538580 12.173.168.195 (8 Dec 2004 12:43:00 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail