C
C#3mo ago
Ewan

✅ Adding a string to a double and then outputting it as a string

if i had string name = ("Hello"); double number = (2.2); how would i add these together and output using console.writeline -----> Hello 2.2 help please!
13 Replies
Ewan
Ewan3mo ago
would i convert the double to a string? how?
Keswiik
Keswiik3mo ago
first off you don't need parenthesis around your assignments string name = "Hello"; is fine
Ewan
Ewan3mo ago
oh of course yeah
Keswiik
Keswiik3mo ago
as for writing them to the console like that, take a look at c# string interpolation: https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/string-interpolation
String interpolation in C# - C#
Learn how to include formatted expression results in a result string in C# with string interpolation.
Servator
Servator3mo ago
Either String Interpolation or StringBuilder If your param count is low use interpolation else StringBuilder is more performant
Ewan
Ewan3mo ago
ah ok thanks!!
MODiX
MODiX3mo ago
Servator
REPL Result: Success
var name = "Ewan"; Console.WriteLine($"Hello, {name}");
var name = "Ewan"; Console.WriteLine($"Hello, {name}");
Console Output
Hello, Ewan
Hello, Ewan
Compile: 408.563ms | Execution: 27.365ms | React with ❌ to remove this embed.
Ewan
Ewan3mo ago
but
Ewan
Ewan3mo ago
No description
Ewan
Ewan3mo ago
this is the problem im having and it says i cant convert type string to float and im using the $ stuff
Servator
Servator3mo ago
pizzaCost is string as you see What's your method's return type?
Ewan
Ewan3mo ago
OH OHHH THE METHOD ok nvm i got it thank you!
Servator
Servator3mo ago
np
Want results from more Discord servers?
Add your server
More Posts