checking for numbers in C#.net

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
Back
Top