|
-
Mar 17th, 2006, 02:05 PM
#1
Thread Starter
Hyperactive Member
To validate an integer ..
is Double.TryParse a better way or use Regular Expression, and why ?
-
Mar 17th, 2006, 07:41 PM
#2
Re: To validate an integer ..
Double.TryParse performs the conversion for you, rather than just telling you whether a conversion is possible. Having said that, it will produce a Double that must still be cobverted to an Integer. Also, TryParse allows you to easily specify the types of numbers that are valid where a regular expression would start to get quite complex. .NET 2.0 has a TryParse method for every numeric type. Finally, using a TryParse method is more self-documenting than using a Regex, which is a more generic operation and you'd have to examine the pattern itself to see exactly what it was doing. In the grand scheme of things I doubt that there's much difference, but TryParse is more specific to the task so I would use it for that reason alone.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|