更新时间:2021-12-02 06:57:20
>我正在学习c#,我想知道如何检查输入是int还是字符串..
>i m learning c# and i want to know how to check if the input is int or a string..
你的问题是有点模棱两可,但是如果你想检查输入的字符串是否是一个整数,你可以尝试将它转换为
整数,如果失败,它不是一个整数:)
Your question is a bit ambiguous, but if you want to check if an inputted string is an integer, you can try converting it to an
integer and if it fails, it's not an integer :)
See the TryParse method:
https://docs.microsoft.com/en-us/dotnet/api/system.int32.tryparse?redirectedfrom=MSDN&view=netframework-4.7.2#System_Int32_TryParse_System_String_System_Int32__
Dave