Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I assume your recipe group defined like this:</p> <pre><code>public class Recipe { public string RecipeName { get; set; } public string IngredientName { get; set; } public Recipe() { } public Recipe(string _recipeName, string _IngredientName) { RecipeName = _recipeName; IngredientName = _IngredientName; } } public class RecipeGroup { public string RecipeName{get;set;} public List&lt;Recipe&gt; Recipe{get;set;} } public class RecipeGroupDictionary { private Dictionary&lt;string, List&lt;Recipe&gt;&gt; data; public RecipeGroupDictionary() { data = new Dictionary&lt;string, List&lt;Recipe&gt;&gt;(); } public bool add(Recipe vr) { this[vr.RecipeName].Add(vr); return true; } public List&lt;Recipe&gt; this[string key] { get { if (!data.ContainsKey(key)) data[key] = new List&lt;Recipe&gt;(); return data[key]; } set { data[key] = value; } } public ICollection&lt;string&gt; Keys { get { return data.Keys; } } public List&lt;RecipeGroup&gt; getRecipeGroup() { var result = new List&lt;RecipeGroup&gt;(); foreach (var key in data.Keys) { result.Add(new RecipeGroup { RecipeName = key, Recipe = data[key] }); } return result; } } class Program { static void Main(string[] args) { var arr = new List&lt;Recipe&gt;(); var recipeGroup = new RecipeGroupDictionary(); arr.Add(new Recipe{ RecipeName="1", IngredientName="A"}); arr.Add(new Recipe{ RecipeName="1", IngredientName="B"}); arr.Add(new Recipe{ RecipeName="1", IngredientName="C"}); arr.Add(new Recipe { RecipeName = "2", IngredientName = "B" }); arr.Add(new Recipe { RecipeName = "2", IngredientName = "C" }); arr.Add(new Recipe { RecipeName = "3", IngredientName = "A" }); arr.Add(new Recipe { RecipeName = "3", IngredientName = "X" }); arr.Add(new Recipe { RecipeName = "3", IngredientName = "Y" }); var rnset = from row in arr where row.IngredientName == "A" select row.RecipeName; var result = (from row in arr where rnset.Contains(row.RecipeName) &amp;&amp; recipeGroup.add(row) //Won't be executed if the first condition is false. select row ).ToArray(); //To array is List&lt;Recipe&gt;, if you don't want recipe group you can remove all the recipe dictionary related. foreach (var key in recipeGroup.Keys) { foreach(var recipe in recipeGroup[key]) Console.WriteLine("RN:{0}, IA:{1}", recipe.RecipeName, recipe.IngredientName); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload