C# testing to see if a string is an integer?

后端 未结 10 1400
北恋
北恋 2020-11-28 12:00

I\'m just curious as to whether there is something built into either the C# language or the .NET Framework that tests to see if something is an integer

if (x         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 12:16

    For Wil P solution (see above) you can also use LINQ.

    var x = "12345";
    var isNumeric = !string.IsNullOrEmpty(x) && x.All(Char.IsDigit);
    

提交回复
热议问题