In this lecture, we will continue the implementation of the CookiesCookbookApp. 1 在这堂课中，我们将继续CookiesCookbookApp的实现。1
One of the challenges will be finding an item in a collection by one of its properties. 2 其中一个挑战将是根据集合中的一个属性在集合中查找项目。2.
Let's now implement reading the list of ingredients from the user. 3 现在，让我们实现从用户读取配料列表。3.
Let's review how this method is supposed to work. In a loop 4 让我们回顾一下这种方法是如何工作的。在循环中4
the user will select IDs of ingredients. 5 用户将选择配料的ID。5.
If anything other than a valid ID is entered, the loop stops and we consider the recipe finished. 6 如果输入了除有效ID之外的任何内容，循环将停止，我们认为配方已完成。6.
Let's start by writing the draft of this loop. 7 让我们从编写这个循环的草稿开始。7.
It looks like many loops we have written before. 8 它看起来像我们以前写过的许多循环。8个
There is a flag deciding whether the loop should stop or not. 9 有一个标志决定循环是否应该停止。9.
Here is the list of ingredients to which we will add any ingredient the user selected and which will finally 10 下面是配料列表，我们将向其中添加用户选择的任何配料，最终将添加10
be returned as the method's result. 11 作为方法的结果返回。11.
The next step is to read the user's input and parse it to an int. 12 下一步是读取用户的输入并将其解析为int。12
If the user input is not parsable to an int, we should stop the execution of the loop. 13 如果用户输入不能解析为int，我们应该停止循环的执行。13个
If it is, we should find the ingredient with the matching ID 14 如果是，我们应该找到具有匹配ID 14的配料
if one exists. The class that stores all the ingredients is the IngredientsRegistry. 15 如果有的话。存储所有配料的类是IngredientsRegistry。15个
So I think it is logical to add a method finding an ingredient by its ID to this class. 16 因此，我认为将根据配料ID查找配料的方法添加到此类中是合乎逻辑的。16年
We'll think about the implementation in a second. 17 我们将在稍后考虑其实现。17
But first, let's think about what should happen if the user enters a number that does not match any 18 但首先，让我们考虑一下，如果用户输入的数字与任何18都不匹配，会发生什么
ingredients ID. 19 配料ID：19
I think in this case this method should return 20 我认为在这种情况下，该方法应该返回20
null. 21 空。21岁
This means we should check here if the selected ingredient is not null and only in this case add to 22 这意味着我们应该在这里检查所选成分是否不为空，并且仅在本例中添加到22
the list of ingredients. 23 配料单。23个
Great. 24 太棒了。24个
Now let's implement the GetById method. 25 现在，让我们实现GetById方法。25个
The simplest way to implement this method is to iterate the collection of all ingredients and return 26 实现此方法的最简单方法是迭代所有配料的集合并返回26
the one with the matching ID. 27 有匹配ID的那个。
If no ingredient is found, we will return null. 28 如果没有找到配料，我们将返回NULL。28
All right, this will work. 29 好了，这会奏效的。29
And I think it is good enough for now. 30 我认为就目前而言，这已经足够好了。30个
Perhaps it's not the optimal solution. 31 也许这不是最优的解决方案。31
We could, for example, remember the ingredient matching a given ID after it was found for the first 32 例如，我们可以记住在找到前32个ID之后与给定ID匹配的配料
time. 33 时间到了。33
But for this we would need another collection type called a dictionary and we'll learn about it later. 34 但对于这一点，我们需要另一种称为词典的集合类型，我们将在稍后了解它。34
So let's leave it as it is. 35 所以我们就让它保持现状吧。35岁
Let's now uncomment the code that uses selected ingredients to create a new recipe. 36 现在，让我们取消对使用选定配料创建新食谱的代码的注释。36
Firstly, let's adjust this line. 37 首先，让我们调整一下这条线。37
Ingredients collection is an IEnumerable. 38 配料集合是一个IEumable。38
So we must use the Count method, not the Count property. 39 因此，我们必须使用Count方法，而不是Count属性。39
I can see we have a typo here. 40 我看得出我们这里有一个打字错误。40岁
I will also comment out the method writing the recipes into a file. 41 我还将注释掉将食谱写入文件的方法。41
Let's see if the recipe will be printed to the console. 42 让我们看看食谱是否会打印到控制台。42
Great. 43 太棒了。43
It seems to be working. 44 它似乎起作用了。44
Let's move on to the next lecture where we will start dealing with writing to and reading from a text 45 让我们继续下一堂课，在那里我们将开始处理课文45的写和读
file. 文件。