如果allIngred
中存在比萨饼的成分,则使用LINQ将得出true
。我将如何去做呢?
string[] allIngred = {
"oil", "yeast", "wheat-flour", "salt", "oil", "baking-powder",
"wheat-flour", "salt", "sugar", "milk"
};
string[] pizza = { "oil", "yeast", "wheat-flour", "salt" };
最佳答案
您可以结合使用All
和Contains
方法来检查pizza
中的所有项目是否都在allIngred
中:
bool result = pizza.All(i => allIngred.Contains(i));