IEnumerable over a Generic List?

Hi all,

I have a Card.cs class that has a card built with a few enum properties. I can make my cards just fine and can select some stuff with LINQ. I have a second class called Deck.cs. This is where I am currently messing up.

namespace MyGame { enum Race { Orc,Elf,Human } enum Subclass {Knight,Rogue,Wizard} public class Card { public Race Race { get; private set; } public Subclass Subclass { get; private set; } public Card(){} public Card(Race race, Subclass subclass) { Race = race; Subclass = subclass; } } public class Deck { public List<Card> Coreset { get { return coreset; } } private List<Card> coreset = new List<Card>(); public List<Card> New() { coreset.Add(new Card(Race.Orc, Subclass.Rogue)); coreset.Add(new Card(Race.Human, Subclass.Wizard)); return coreset; } public void Shuffle() { coreset = coreset.Orderby(card => Guid.NewGuid()) .ToList(); } } 

}

Then, in Program.cs, I do:

var deck = new Deck(); deck.New(); deck.Shuffle(); // more stuff... IEnumerable<Card> orcs = deck.Coreset .Where(e => e.Race == Race.Orc).ToList(); 

This just doesn't sit right… I know this is a pile and want to know what people should recommend I read from here. Any suggestions? I think in Deck.cs I want to implement IEnumerable<List<Card>> . Does that sound right at all…?

by blackcamo via /r/csharp

Leave a Reply