Check if a string has at least one number in it using LINQ

后端 未结 5 975
既然无缘
既然无缘 2020-12-04 21:07

I would like to know what the easiest and shortest LINQ query is to return true if a string contains any number character in it.

5条回答
  •  庸人自扰
    2020-12-04 21:14

    "abc3def".Any(c => char.IsDigit(c));
    

    Update: as @Cipher pointed out, it can actually be made even shorter:

    "abc3def".Any(char.IsDigit);
    

提交回复
热议问题