C
C#8mo ago
Ewan

✅ Taking a value out of a method and putting it into another

For this, i want the value inside price() that is the currentPizzaPrice and i want it to go into the totalPrice() method, how can i do this?
No description
6 Replies
Angius
Angius8mo ago
Return that value from this method Instead of returning a string
Ewan
EwanOP8mo ago
but i want the string to be returned, is there a way to take it out without changing the returned value?
Angius
Angius8mo ago
Well, you can return, say, a record or a class that contains both
Servator
Servator8mo ago
You can always override ToString() method
Angius
Angius8mo ago
Or even a tuple That said, i would definitely be better if you were to return the bare value and add the string thingamajigs to it only when displaying it So instead of
string price = Price();
Console.WriteLine(price);
string price = Price();
Console.WriteLine(price);
you'd just do
float price = Price();
Console.WriteLine($"€{price}0");
float price = Price();
Console.WriteLine($"€{price}0");
Or whatever else you need
Ewan
EwanOP8mo ago
ohhh alright that makes sense, thanks!
Want results from more Discord servers?
Add your server