Fastest way to check if string contains only digits

后端 未结 20 870
挽巷
挽巷 2020-12-04 09:07

I know a few ways how to check this. regex,int.parse,tryparse,looping.

can anyone tell me what is the fastest way to check?

the nee

20条回答
  •  情深已故
    2020-12-04 09:36

    You can do this in a one line LINQ statement. OK, I realise this is not necessarily the fastest, so doesn't technically answer the question, but it's probably the easiest to write:

    str.All(c => c >= '0' && c <= '9')
    

提交回复
热议问题