IsNumeric C# equivalent

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
Actually, IsNumeric does two things: converts a string and returns a boolean
true if the resulting expression is recognized as a number. Parse only
converts a string representation of a number to double. I need the boolean
return to validate a text box entry that can't be easily checked with a
validator.
Stephan.
 
That's the idea. However, I need to do that on a string. I guess I could use
the String.ToCharArray() method first or use a loop.
Thanks,
Stephan.
 
Check Parse and TryParse methods for corresponding types, Int, Long etc.

HTH
Alex
 
I apologize, I read TryParse too fast. You're right, it does what I need.
Thank you,
Stephan.
 
So, check TryParse

MSDN:
The TryParse method is like the Parse method, except this method does not
throw an exception if the conversion fails. If the conversion succeeds, the
return value is true and the result parameter is set to the outcome of the
conversion. If the conversion fails, the return value is false and the
result parameter is set to zero.



HTH

Alex
 

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

Back
Top