From 50f2cb43a48fd474f63f7e7380a7d9f07356e736 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Mon, 10 Apr 2023 01:39:30 +0200 Subject: [PATCH] :bug: fix: RecipeCollection is now correctly enumerable --- MCTG/MCTGApp/Program.cs | 4 ++-- MCTG/MCTGLib/RecipeCollection.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MCTG/MCTGApp/Program.cs b/MCTG/MCTGApp/Program.cs index 57a3a18..9998a9b 100644 --- a/MCTG/MCTGApp/Program.cs +++ b/MCTG/MCTGApp/Program.cs @@ -29,7 +29,7 @@ Console.WriteLine("test overload of [] operator:"); try { rc[2].DisplayId(); - rc.GetById(14).DisplayId(); + rc.GetById(110).DisplayId(); } catch (ArgumentNullException) { @@ -51,5 +51,5 @@ RecipeCollection rc2 = new RecipeCollection( Console.WriteLine("test of Enumerable property:"); foreach (Recipe r in rc2) { - r.DisplayId(); Console.Write(" - "); + r.DisplayId(); } diff --git a/MCTG/MCTGLib/RecipeCollection.cs b/MCTG/MCTGLib/RecipeCollection.cs index c9ed6be..0611a0f 100644 --- a/MCTG/MCTGLib/RecipeCollection.cs +++ b/MCTG/MCTGLib/RecipeCollection.cs @@ -39,7 +39,7 @@ namespace Model public RecipeCollection(params Recipe[] recipes) : base(ComputeId()) { - _recipes.CopyTo(recipes, 0); + _recipes = new List(recipes); } #endregion @@ -116,7 +116,7 @@ namespace Model IEnumerator IEnumerable.GetEnumerator() { - return _recipes.GetEnumerator(); + return this.GetEnumerator(); } #endregion