Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve bool result by using LinQ code

Tags:

c#

linq

If the ingredients of a pizza exist among allIngred, the result would give true by using LINQ. How would I go about doing this?

string[] allIngred = {
    "oil", "yeast", "wheat-flour", "salt", "oil", "baking-powder",
    "wheat-flour", "salt", "sugar", "milk"
};
string[] pizza = { "oil", "yeast", "wheat-flour", "salt" };
like image 798
What'sUP Avatar asked Jan 23 '26 21:01

What'sUP


1 Answers

You can use a combination of the All and Contains methods to check that all items in pizza exist in allIngred:

bool result = pizza.All(i => allIngred.Contains(i));
like image 90
Ahmad Mageed Avatar answered Jan 26 '26 12:01

Ahmad Mageed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!