cancel
Showing results for 
Search instead for 
Did you mean: 

Not quite gaming.

Antronman
Level 10
In C#, what would be the equivalent of a Console.Readline(); command for integers, not strings? I'm having trouble creating a calculator. I know it isn't quite gaming, but if anybody could help me I would appreciate it.
Say hi to the next generation.

Peace is a lie, there is only Passion

Through passion, I gain strength

Through strength, I gain victory

Through victory, my chains are broken

The Republic of Gamers shall free me
213 Views
4 REPLIES 4

danskieness
Level 10
its the same i believe. i might be wrong but im pretty sure it's still console.readline() pass your integer to a variable.
Mobo : Asus Maximus VI Impact || CPU : i5-4670k || Cooling : H100
GPU : MSI GTX 970 Gaming 4G || PSU : Corsair RM 650 || Rams : G Skill Trident X 4GBx2 2400 CL10
Monitor : 2x Asus VX239h + 1x HP w2207h || Chassis : Bitfenix Prodigy Red || OS : WIN8.1 x64
Periphirals : Corsair K95, Logitech g402, Edifier 3350

danskieness wrote:
its the same i believe. i might be wrong but im pretty sure it's still console.readline() pass your integer to a variable.

It isn't. Using Visual Studios 2008, In the error list it shows that the compiler "cannot convert integer to string" at the line in which the console.readline() command is.
Say hi to the next generation.

Peace is a lie, there is only Passion

Through passion, I gain strength

Through strength, I gain victory

Through victory, my chains are broken

The Republic of Gamers shall free me

CloudD901
Level 9
C# can only read strings from the console I believe.
Console.ReadLine();
You can then convert it to an int:
int test = Convert.ToInt32(Console.ReadLine());

You can always play it safe by verifying the content of the ReadLine command to make sure that it is all numbers before using Convert:
string Str = Console.ReadLine();
double Num;
bool isNum = double.TryParse(Str, out Num);
if (isNum)
MessageBox.Show(Num.ToString());
else
MessageBox.Show("Invalid number");

Arne_Saknussemm
Level 40
My ancient greek is a bit rusty so I don't quite understand any of that post but seems rep worthy...

🙂