如果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" };

最佳答案

您可以结合使用AllContains方法来检查pizza中的所有项目是否都在allIngred中:

bool result = pizza.All(i => allIngred.Contains(i));

09-10 19:44