// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public static class Util { public static T EnumParse(string s) where T : struct { return (T)Enum.Parse(typeof(T), s); } } public enum Suit { Hearts, Clubs, Diamonds, Spades } public class Card { public Suit Suit { get; set; } public int Value { get; set; } public override string ToString() { return Value + " of " + Suit; } } public class CardList { private List list = new List(); public void Add(Card card) { list.Add(card); } public override string ToString() { return "(" + String.Join(",", list.ConvertAll(elm => elm.ToString()).ToArray()) +")"; } } public class Program { public static void Main(string[] args) { CardList list = new CardList(); Console.WriteLine(list); list.Add(new Card { Suit = Suit.Clubs, Value = 8 }); Console.WriteLine(list); list.Add(new Card { Suit = Util.EnumParse("Spades"), Value = int.Parse("9") }); Console.WriteLine(list); } } }