❔ ✅ "Cannot convert from int to string" why cant I take away these values??
the code underlined in red gives me this message, why doesnt the subtraction work?
7 Replies
Console.WriteLine
expects a string, you're giving it an intits in brackets? then why does the trainnumber on the right work?
long explaination but essentially
Console.WriteLine
can take any amount of arguments, and it doesn't care about the type of any arguments besides the first
If you want to make a string out of that then you'll need to use interpolated strings. ah i see thanks!
yeah, it's trying to invoke one of these overloads:
https://learn.microsoft.com/en-us/dotnet/api/system.console.writeline?view=net-7.0#system-console-writeline(system-string-system-object-system-object-system-object)
https://learn.microsoft.com/en-us/dotnet/api/system.console.writeline?view=net-7.0#system-console-writeline(system-string-system-object())
which is why it wants your first argument to be a string
the subtraction itself is totally fine and does produce an
int
, but that's not what Console.WriteLine()
wantsok i gotcha, thank you!
Closed!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.