c# - Why does Console.Read() not give the value I expect for integer input? -
For some reason, VSE C # 2010 (or maybe there is a problem with my laptop) <,>, & gt; , & Lt; = And> = Boolean Comparison operator correctly
Fixed zero main (string [] args) {Console.WriteLine ("Enter an integer:"); Int myInt = Convert.ToInt32 (console. Read ()); Boole's Leighton 10 = Myint & lt; 10; Bull is Bitin 0 and 5 = (0
Enter an integer: 2 integer less than 10? Integer lie between 0 and 5? Is A True Truth A Lie? False
console Read
in a single character and returns the ASCII value of that character; the ASCII value of the character is not 2
2
.
You want to read in character and represent it as a character , which you can do through the use of the console. Readkey
(as you do in your program later) or console.readline
if you want to read a string instead of using the console, such as the interpretation Has been. Read
. You can then convert that number to the numerical representation by using the representation of that string using int.Parse
.
Comments
Post a Comment