Creating a deck of cards is a fun beginners problem, and I'm interested in seeing creative ways others have done it. Here's my stab at it in C#:
Code:
private List<KeyValuePair<Suits, byte>> createDeck()
{
List<KeyValuePair<Suits, byte>> deck = new List<KeyValuePair<Suits, byte>>();
for (byte i = 0; i < 52; i++)
{
Suits suit = i % 2 == 0 ? i % 4 == 0 ? Suits.Diamond : Suits.Heart : i % 4 == 1 ? Suits.Spade : Suits.Club;
deck.Add(new KeyValuePair<Suits, byte>(suit, (byte)(i % 13)));
}
return deck;
}
public enum Suits
{
Club,
Diamond,
Heart,
Spade
}