C
C#2y ago
vl4do

❔ 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
Angius
Angius2y ago
Cards should simply be objects
vl4do
vl4doOP2y ago
Im not familiar with objects nervousowo
Pobiega
Pobiega2y ago
can return a tuple then. Looks like public (bool foo, int bar) MethodName()...
vl4do
vl4doOP2y ago
how do i return them to the main?
Angius
Angius2y ago
Call the method
vl4do
vl4doOP2y ago
like dealerHand = ... hasAce = ....
Angius
Angius2y ago
var thing = MethodName();
var foo = thing.foo;
var bar = thing.bar;
var thing = MethodName();
var foo = thing.foo;
var bar = thing.bar;
Or shorter,
var (foo, bar) = MethodName();
var (foo, bar) = MethodName();
vl4do
vl4doOP2y ago
so my code should look like var (dealerHand, dealerHasAce) = DrawCard(dealerHasAce, "dealer", dealerHand, cards); ? sorry idk how to do this rectangle around the code
Pobiega
Pobiega2y ago
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
vl4do
vl4doOP2y ago
they do so just (dealerHand, dealerHasAce) = DrawCard(dealerHasAce, "dealer", dealerHand, cards); ?
Pobiega
Pobiega2y ago
mhm its ` btw
vl4do
vl4doOP2y ago
ty
Angius
Angius2y ago
$code
MODiX
MODiX2y ago
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/
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server