How can I check if a string is a number?

后端 未结 25 1853
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 21:04

I\'d like to know on C# how to check if a string is a number (and just a number).

Example :

141241   Yes
232a23   No
12412a   No

an

25条回答
  •  心在旅途
    2020-11-27 21:18

    Yes there is

    int temp;
    int.TryParse("141241", out temp) = true
    int.TryParse("232a23", out temp) = false
    int.TryParse("12412a", out temp) = false
    

    Hope this helps.

提交回复
热议问题