Julien Julien - 6 months ago 21
C# Question

C# - Field values of an array picking up values of a loop

I'm training C# on a simple card game. I have methods that shuffle and deals the cards. I have a random deck that is well generated.
Is it possible to set an array for the player1 cards, picking up the first ten values of the array.
Here is a part of my code :

currentCard = 0;
public Card DealCard()
if (currentCard < deck.Length)
return deck[currentCard++];
return null;

I want to pick up for example ten first values of


Any suggestions will be appreciated, thanks for your help !

Answer Source

You mean you want to pull the first 10 enties into another array? Something like;

var player1Cards = deck.Take(10);


List<int> player1Cards = new List<int>();
for (int i = 0; i < 10; i++){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download