Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > IsNumeric C# equivalent

Reply
Thread Tools

IsNumeric C# equivalent

 
 
Crusoe Crusoe is offline
Junior Member
Join Date: Mar 2011
Posts: 1
 
      03-22-2011
The old IsNumeric function is still available in .NET

Add a reference to Microst.Visualbasic and use the Information.IsNumeric function.

e.g.

using Microsoft.VisualBasic;
Code:
    private void button1_Click(object sender, EventArgs e) {
      string s = "1";
      if (Information.IsNumeric(s)) {
        MessageBox.Show("yes it's a number");
      }   
    }

P.S. I know this is a 7 year old thread, but, this page is the first one that appears if you Google for C# IsNumeric and it does not have a correct answer. Just trying to fight pollution of the internet.
 

Last edited by Crusoe; 03-22-2011 at 06:55 AM..
Reply With Quote
 
 
 
 
JBobbins JBobbins is offline
Junior Member
Join Date: Jan 2012
Posts: 2
 
      01-13-2012
This seems to work well:

Code:
public static bool IsNumeric(object o)
{
	double result;
	return o != null && Double.TryParse(o.ToString(), out result);
}
 

Last edited by JBobbins; 01-13-2012 at 05:50 PM.. Reason: add a note
Reply With Quote
 
 
 
 
daniefvh daniefvh is offline
Junior Member
Join Date: Jan 2012
Posts: 1
 
      01-26-2012
int test = 0;
if (!int.TryParse(Position,test))
{
// Is a Number
}
else {
// Not a number
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any IsNumeric in C#? Steve Kershaw ASP .Net 10 02-03-2012 03:27 AM
Import Microsoft.VisualBasic for IsNumeric? =?Utf-8?B?RGF2ZQ==?= ASP .Net 8 01-17-2006 01:56 AM
Name 'IsNumeric' is not declared??? David Lozzi ASP .Net 4 12-07-2004 01:35 AM
IsNumeric Function =?Utf-8?B?TXJNaWtl?= ASP .Net 5 11-29-2004 02:51 PM
Isnumeric and importing vb functions martin ASP .Net 3 07-19-2004 11:41 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57