예제 #1
0
        public override string ToString()
        {
            StringBuilder output  = new StringBuilder();
            string        shortId = $"{this._id.ToString().Substring(this._id.ToString().Length - 6)}";

            // Print out the counts of each type of animal
            var counts = Plants.GroupBy(plant => plant.Type)
                         .Select(group => new PrintReport
            {
                Name  = group.Key,
                Count = group.Count()
            });



            output.Append($"Plowed field {shortId} has {this._plants.Count} plants\n");
            // this._plants.ForEach(a => output.Append($"   {a}\n"));

            foreach (PrintReport report in counts)
            {
                output.Append($"  {report.Name}: {report.Count}\n");
            }

            return(output.ToString());
        }