checking for numbers in C#.net

G

Guest

Hello,
Is there a command in C# which will allow me to check whether or not a
variable is a number? Something similar to the VB isNumeric command?

Thanks,
Ben
 
S

Stoitcho Goutsev \(100\)

What do you mean by that?
You have an object that you want to test if it is of type Int32, double, etc
numeric types or you have a string and you want to check whether it
represent a correct number?


For the first case what comes to my mind is to write a method that will
first call

obj.GetType.IsPrimitive

If the type of the object is one of the promitive you just need to filter
out the two types that are not numeric - Char and Boolean
 
G

Guest

What I mean is I want to check a variable and determine whether that
variable is a string or an Int32. The Int32.TryParse method that Chris
posted does exactly what I needed.

Thanks,
ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top