コード例 #1
0
        public (SelectResult Result, TShirt Shirt) SelectRandomShirt()
        {
            var keys = _stock.Keys.ToList();

            if (keys.Count == 0)
            {
                return(SelectResult.NoStockLeft, null);                    // all shirts sold
            }
            Thread.Sleep(Rnd.NextInt(10));
            string selectedCode = keys[Rnd.NextInt(keys.Count)];

            bool found = _stock.TryGetValue(selectedCode, out TShirt shirt);

            if (found)
            {
                return(SelectResult.Success, shirt);
            }

            else
            {
                return(SelectResult.ChosenShirtSold, null);
            }
            //return _stock[selectedCode];
        }