C
C#13mo ago
krfx

✅ whats wrong?

using System; public class Program { public static void Main(int[] args) { Console.WriteLine("> Converteste minute in secunde:"); int input = Console.ReadLine(); Console.WriteLine(input * 2); } } it says it cant convert string to int but why
3 Replies
SinFluxx
SinFluxx13mo ago
Console.ReadLine() returns a string not an int, so your code would need to try and parse an int from what Console.ReadLine() gives you
Teddy
Teddy13mo ago
you can use int input = int.Parse(Console.ReadLine()); but like @sinfluxx said, TryParse would be better, because what if they don't enter a whole number, or spaces on the end, letters, etc. https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-7.0#system-int32-tryparse(system-string-system-int32@) Scroll down to Examples
krfx
krfxOP13mo ago
thanks
Want results from more Discord servers?
Add your server