0
How do I convert string to int?
This is my code: int number = Console.ReadLine(); if (number == 1) { Console.WriteLine("Good"); } But I have an error: cannot implicitly convert type 'string' to 'int' I do not know what to do. Please help.
5 Respostas
+ 5
Console inputs in c# are always string.
Try using Convert.toInt32(Console.ReadLine() ) ;
This will convert the input string to int.
Likewise you need to convert your console inputs to required datatypes as it will always be string
+ 4
int number = int.Parse(Console.ReadLine());
or
int number;
int.TryParse(Console.ReadLine(), out number);
+ 3
Welcome @Luke Hegelund, happy to help☺️
+ 1
Thanks, Shraddha, that really helped!
0
fetched out every character out off the string and convert it into ascii code by using array and for loop