✅ 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
Console.ReadLine()
returns a string
not an int
, so your code would need to try and parse an int from what Console.ReadLine()
gives youyou 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 Examplesthanks