Is there a C# Function that is similar to the VB IsNumeric function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clflyer
    New Member
    • May 2010
    • 5

    Is there a C# Function that is similar to the VB IsNumeric function

    Visual Basic has a function IsNumeric.
    It returns True if the argument is a number, false if not.

    in VB code it would look like this:

    Code:
    Dim txt as string = me.Textbox1.Text
    if IsNumeric(txt)
    	MsgBox("Its a number.");
    else 
    	MsgBox("Its not a number.");
    end if
    What I'm looking for is a similar function in C#

    Thanks,
    Bill
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    For all those people who find it more convenient to bother you with their question rather than to Google it for themselves.


    ;)

    A TryParse on the type you want it to go to may also work.

    Comment

    • clflyer
      New Member
      • May 2010
      • 5

      #3
      Thanks That works .

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I would say for a generic "numeric", use Double.TryParse (), It takes +/- values of integer or float types.

        Comment

        Working...