C
C#3mo 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
Angius3mo ago
Return that value from this method Instead of returning a string
Ewan
Ewan3mo ago
but i want the string to be returned, is there a way to take it out without changing the returned value?
Angius
Angius3mo ago
Well, you can return, say, a record or a class that contains both
Servator
Servator3mo ago
You can always override ToString() method
Angius
Angius3mo 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
Ewan3mo ago
ohhh alright that makes sense, thanks!
Want results from more Discord servers?
Add your server
More Posts