我列出了几种成分:
List<string> vegList = new List<string>();
其中有一些字符串,例如:“樱桃”,“黄油”,“面包”。
我的想法是拥有一本字典或类似带有食谱字符串的内容,如果该食谱中有一个或多个元素,则返回该食谱的名称。
我尝试制作字典和数组,但没有得到想要的东西。 有人可以帮忙吗?
我尝试了这个,但我不知道该怎么办了
myString = "receit pineapple cake, cherry, bread ..."
foreach(string item in vegList )
{
if(item.Contains(myString))
return item;
}
If each recipe has a
vegList
, or more specifically, you have aRecipe
class with aList<string> vegList field
, and let's say you have aList<Recipe> recipes
somewhere:matches
will be aList<Recipe>
with recipes containing "cherry" as an ingredient.