Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In C, passing a struct by value effectively gives a copy of the struct to the called routine; regardless of what the routine does with its copy of the struct, the fields of the caller's struct will be unaffected. If you want the called function to be able to modify the struct, you must make it a "ref" parameter.</p> <p>Note that passing a struct as a ref parameter has tighter semantics than passing a class-object reference. A routine that is given a reference to a class object may not only do whatever it wants with the reference, but it can make it available to other code that may do whatever it wants <i>whenever it wants</i>, even after the function that was originally given the reference has returned. By contrast, a routine which is given a struct as a ref parameter may do whatever it wants with the struct until it returns, but it will have no ability to directly or indirectly modify the fields of the struct after it returns.</p> <p>You don't show the contents of your 'Player' data type, so it's not clear whether it should be a struct or a class. The player's hand, however, would seem to be a logical candidate for a struct since it simply holds two cards. Making it a mutable class would seem really icky to me. One could either make the player's hand an immutable struct and replace the <code>Deal_Cards</code> method with a <code>GenerateHand</code> function that returns a <code>playerHand</code> struct, or else pass a <code>playerHand</code> to a <code>DealCards</code> as a ref parameter. If one goes the 'immutable' route, one could use a class, but I see little benefit in using an immutable class instead of an immutable struct in this context.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload