---
title: "IsNumeric() hell"
url: "https://osherove.com/blog/2003/9/14/isnumeric-hell-1.md"
canonical: "https://osherove.com/blog/2003/9/14/isnumeric-hell-1.html"
published: "2003-09-14T19:14:00"
updated: "2003-09-14T19:14:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "As an old VB'er I have to ask - what's up with the lack of IsNumeric() in the base class library? Why is there a Char.IsNumber() but no string.IsNumeric()? Why should I have to reference Microsoft.VisualBasic.Dll for…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# IsNumeric() hell

By Roy Osherove September 14, 2003 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published September 14, 2003; technical details may be outdated.

As an old VB'er I have to ask - what's up with the lack of **IsNumeric()** in the base class library? Why is there a Char.IsNumber() but no string.IsNumeric()? Why should I have to reference Microsoft.VisualBasic.Dll for this “special” feature? (BTW - there's no harm in referencing that dll, it's a part of the framework just like System.XML is, but still...)

Here's a [long and thorough discussion](http://tulsadnug.org/Forums/ShowPost.aspx?PostID=624) on the various “workarounds” needed to have this simple functionality implemented. Highlights:

- Use the _Microsoft.VisualBasic_ namespace(easy and clean, but why so far away?)
- Convert the string to a char array and check each item using _Char.IsNumber()_
- Convert the string to a char array and check each item using _if (arr\[i\] > 57 || arr\[i\] < 48) return false;_
- Try a conversion and use a _Try-Catch_ block to check for no- success(the worst performance option)
- Use _Double.TryParse()_ to return a boolean for success (now why don't we have this for the other types?)
- (added later:) Yeah, you can also use a regular expression to check for a numeric.

Are we done yet?

This reminds me of a joke (which you surely know):

_NASA spent $12 million for a space pen that can write upside down while the russians just used a pencil.
_

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Sep 18, 2003

    ### [RegexLib RSS now even cooler](https://osherove.com/blog/2003/9/18/regexlib-rss-now-even-cooler.html)

- Sep 15, 2003

    ### [I'm in the "contributor spotlight" on MSDNAA](https://osherove.com/blog/2003/9/15/im-in-the-quotcontributor-spotlightquot-on-msdnaa.html)

- Sep 14, 2003

    ### [IsNumeric() hell](https://osherove.com/blog/2003/9/14/isnumeric-hell.html)

- Sep 11, 2003

    ### [Document outline](https://osherove.com/blog/2003/9/11/document-outline.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
