❔ Return two values from a method
So im making a blackjack game and i have a method where the player or the dealer draws cards. I want to implement aces and i thought that making a boolean and checking if the drawed card is an ace is the best method but i dont know how to return 2 values from a method. I researched it and i found 3 things: out, ref and tuples. Didnt understand none of them. Can someone help me? Also any other advice on the code would be greatly appreciated!
Code: https://paste.mod.gg/jriutqhrhrvq/0
BlazeBin - jriutqhrhrvq
A tool for sharing your source code with the world!
15 Replies
Cards should simply be objects
Im not familiar with objects
can return a tuple then.
Looks like
public (bool foo, int bar) MethodName()
...how do i return them to the main?
Call the method
like dealerHand = ...
hasAce = ....
Or shorter,
so my code should look like
var (dealerHand, dealerHasAce) = DrawCard(dealerHasAce, "dealer", dealerHand, cards); ?
sorry idk how to do this rectangle around the code
not quite
you can't pass the values in if you are also getting them out like that
or rather, you can, if they already exist before
but then you drop the
var
they do
so just
(dealerHand, dealerHasAce) = DrawCard(dealerHasAce, "dealer", dealerHand, cards);
?mhm
its ` btw
ty
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/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.