C
C#7mo 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
EwanOP7mo ago
would i convert the double to a string? how?
Keswiik
Keswiik7mo ago
first off you don't need parenthesis around your assignments string name = "Hello"; is fine
Ewan
EwanOP7mo ago
oh of course yeah
Keswiik
Keswiik7mo 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
Servator7mo ago
Either String Interpolation or StringBuilder If your param count is low use interpolation else StringBuilder is more performant
Ewan
EwanOP7mo ago
ah ok thanks!!
MODiX
MODiX7mo 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
EwanOP7mo ago
but
Ewan
EwanOP7mo ago
No description
Ewan
EwanOP7mo ago
this is the problem im having and it says i cant convert type string to float and im using the $ stuff
Servator
Servator7mo ago
pizzaCost is string as you see What's your method's return type?
Ewan
EwanOP7mo ago
OH OHHH THE METHOD ok nvm i got it thank you!
Servator
Servator7mo ago
np
Want results from more Discord servers?
Add your server