Loading...
Nasko13 avatar Nasko13 0 Точки

C# how to set a particular type of input

For example i want the user to enter an integer between 0 and 200, but lets say he enters 257 (for example). What is the command that i can use so the console only accepts between 0 and 200 apart from the "try - catch" command? 

Thank YOU!

Тагове:
0
Module: C# Advanced
RoYaL avatar RoYaL Trainer 6849 Точки

You can manipulate the cursor, window and the size of the console. Also you can accept a char per key, instead of waiting for "enter" to be pressed. So you can make logical checks after each key pressed and depending on the result so far, you can decide whether to allow the user to click the next key or not.

For example you have to receive three character one after another: '2', '0', '0'. When the user enters for the first char '1', you are perfectly comfortable to make them enter any other numeric character afterwards, because either it is '1','9','9' or '1','0','0' it does not matter. But the user enters '2' for the first one. Then they enter '0'. At this stage, you can allow them to enter only '0' or [ENTER] (20, or 200).

If after '2', they enter, let's say, '7', you do not allow them to enter any other third character, but only [ENTER] to be pressed.

As you can manipulate the colors of the console, you can color the output with different one if they enter illegal character.

You can check Console.ReadKey() for reference.

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.