C
C#13mo 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
Angius13mo ago
Cards should simply be objects
vl4do
vl4do13mo ago
Im not familiar with objects nervousowo
Pobiega
Pobiega13mo ago
can return a tuple then. Looks like public (bool foo, int bar) MethodName()...
vl4do
vl4do13mo ago
how do i return them to the main?
Angius
Angius13mo ago
Call the method
vl4do
vl4do13mo ago
like dealerHand = ... hasAce = ....
Angius
Angius13mo 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
vl4do13mo 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
Pobiega13mo 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
vl4do13mo ago
they do so just (dealerHand, dealerHasAce) = DrawCard(dealerHasAce, "dealer", dealerHand, cards); ?
Pobiega
Pobiega13mo ago
mhm its ` btw
vl4do
vl4do13mo ago
ty
Angius
Angius13mo ago
$code
MODiX
MODiX13mo 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
Accord13mo 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
More Posts