Working on my first OOP project. I have initialized a list of cards with value and suit. So I have a list of 52 objects. I need to shuffle. I have given each object a field named ShuffleRank. I have given each card a random value between 1-100. Now I want to sort the deck by this value and return a new deck. I've tried OrderBy and Sort, but I'm having type issues. Here's my deck class:
namespace BlackJack
{
public class Deck
{
//This needs to be public on the get side to be visible outside
//of the Deck object
public List<Card> Cards { get; private set; }
public List<Card> Shuffled { get; set; }
Random rnd = new Random();
public Deck()
{
NewDeck();
}
private void NewDeck()
{
Cards = new List<Card>();
for (var i = 0; i < 4; i++)
{
for (var j = 2; j < 13; j++)
{
Cards.Add(new Card { Suit = (Suit)i, Value = (CardValue)j });
}
}
}
public void shuffleCards()
{
foreach (var Card in Cards)
{
Card.ShuffleRank = rnd.Next(100);
Shuffled = Cards.Sort().......
}
}
}
}