cost 83 ms
尝试解析 C# 无限次让用户输入数字? - Try-parse C# infinite amount of times for user to enter a number?

我正在尝试学习如何使用TryParse (我对编程很陌生,所以如果这是一个愚蠢的问题,我很抱歉。)? 我想这样做是为了让用户可以再试多少次,我想我可以用一个while循环和try-catch来做到这一点。 但我想学习如何使用 Try-parse 如果可能的话,我尝试使用 if else 语句进行 ...

2021-11-25 17:11:21   2   47    c# / tryparse  
如何在 Python 3 中进行尝试解析,如果输入了字符串而不是 int,则会给出一条消息,并让用户有机会重试? - How to make a try-parse in Python 3 that gives a message if string instead of int is entered and that gives the user the chance to try again?

我正在尝试在 Python 3 中进行尝试解析。它可以正常工作(如果我输入一个 int 它会返回我输入的内容,如果我输入一个字符串它会给出错误)但我想返回一条消息如果我输入一个字符串而不是 int,用户会从计算机获取错误消息。 例如 print("Error. Please enter a num ...

正 integer 的 tryparse 方法未返回非整数输入的错误 - tryparse method for positive integer is not returning an error with inputs that are not integers

我有以下代码: 目标是当输入不是正数 integer 时,继续返回错误。 一旦输入为正 integer,继续。 问题是这个逻辑只适用于负数。 当我尝试将代码变为while(.int,TryParse(ReadLine(), out orderQuantity) && orderQua ...

使用 tryparse 的 do-while 循环不会转到 else 语句 - Do-while loop with tryparse not going to the else statement

无法通过谷歌搜索解决我的问题,所以我想我会把它带到这里试试运气。 我是 c# 的新手,正在编写一个随机生成数字的程序,用户可以猜测直到它正确为止。一切运行顺利,但问题是如果输入的是字母而不是数字,则 else 语句不是触发并且它不会向用户提供错误消息,它只是转到第一个 if 语句。 这是代码,感谢任 ...

如何在比较指令 C# WPF 中使用 int.TryParse? - How can I use int.TryParse in comparison instruction C# WPF?

我有两个 IntegerUpDown 控件,我需要在MouseLeave_Event中进行比较,我使用了int.Parse但是当我尝试这段代码时出现异常: 例外: 我在 Stackoverflow 中搜索了避免此异常的解决方案,我看到最好的解决方案是使用int.TryParse ,但我不知道如何在 ...

DateTimeOffset TryParse 不接受有效的日期时间 - C# OWIN 实现 - DateTimeOffset TryParse not accepting valid datetime - C# OWIN implementation

我正在使用 C# OWIN 框架进行身份验证,并且我有 TokenEndpoint 覆盖方法,它以正确的格式转换 IssuedDate 和 ExpiresDate,所以我使用 DateTimeOffset.TryParse 方法来检查和返回日期时间,所以现在我面临的问题是真的很奇怪,其中一项服务正常 ...

TryParse 方法正在读取负值并将其转换为 VB.Net 代码中的正 0 - TryParse method is reading negative value and turning it to a positive 0 in VB.Net code

我创建此代码是为了获得这些值的总和。 问题是我有一个负值作为数量之一,当我尝试执行 TryParse 方法将字符串数量转换为双精度值时,该值变为 0 作为正整数而不是前一个值($26,652.25) 或 -$26,652.25 这弄乱了本应更少的总数。 总金额显示为 989,992.74 美元, ...

为什么我的未初始化变量在 TryParse 中设置其值后再次变为未分配状态? - Why does my uninitialised variable become unassigned again after it has its value set inside of TryParse?

变量 inputBool 在 while 循环外声明,然后在我尝试将 userInput 解析为布尔值时在 while 循环内设置。 一旦 while 循环退出, inputBool 将再次变为未声明状态! 但是,如果我用一个值 (EG false) 初始化 inputBool 变量,它将在 wh ...

枚举的定义没有从索引中给出值 - Enum Is Defined not giving value from Index

亲爱的朋友们, 从上面的示例中可以看出,我遇到了一个奇怪的问题。 我们有一个枚举类型,我们希望确保枚举值存在。因此,我在 Microsoft 文档中阅读过,我们可以使用 IsDefined 方法来确保存在。 我实现了这一点,我可以看到当我们传递“Meter”字符串时它返回正确的值,但如果我传递“1” ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM