How to check if my string only numeric

后端 未结 7 2063
臣服心动
臣服心动 2020-12-18 17:49

How I can check if my string only contain numbers?

I don\'t remember. Something like isnumeric?

7条回答
  •  情话喂你
    2020-12-18 18:37

    You con do like that:

    public bool IsNumeric(string val)
    {
        if(int.TryParse(val)) return true;
        else if(double.TryParse(val)) return true;
        else if(float.TryParse(val)) return true;
        else return false;
    }
    

提交回复
热议问题