如何检查用户输入的输入是否为c#中的int? [英] How to check if the entered input by the user is int in c#?

查看:157
本文介绍了如何检查用户输入的输入是否为c#中的int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习c#,我想知道如何检查输入是int还是字符串..

i m learning c# and i want to know how to check if the input is int or a string..

推荐答案

>我正在学习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 :)

请参阅TryParse方法:

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__

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


这篇关于如何检查用户输入的输入是否为c#中的int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆