Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You cannot limit the user only put in a-z chars on the console - you have to check the input, he can write in any character (just think about when the input is redirected to your program from a file with &lt;, e.g. yourapp.exe &lt; input.dat ). </p> <p>But its easy to check a character is lowercase a-z letter. E.g. with plain, ASCII, C tactic (I will use your defined variables):</p> <pre><code>if('A' &lt;= pre3 &amp;&amp; pre3 &lt;'Z') { // pre3 was made upper in your code // input OK } else { // input NOK } </code></pre> <p>With regex:</p> <pre><code>Regex r = new Regex(@"^[a-zA-Z]$"); return r.IsMatch(pre); </code></pre> <p>If you cannot allow case-insensitive characters, just change the code I wrote.</p> <p>Anyway, I think you need Console.Read() (ReadKey also read keys like arrows, F1-F12 etc..., so ALL keys, even tab and caps lock). Refer to MSDN: <a href="http://msdn.microsoft.com/en-us/library/system.console.read.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.console.read.aspx</a></p> <p>And maybe you should use this function, if you would support unicode letters: <a href="http://msdn.microsoft.com/en-us/library/yyxz6h5w.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/yyxz6h5w.aspx</a> Note that unicode letters are usually not one bytes! But char can store it. These letters are for example beautiful Hungarian letters with acutes and these king of things: á, é, ő, ű, ö, ü etc (but also French have a lot, and also Dutch etc...)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload