title: C# LINQ - Filtering by list-type property within a class
body: <p>I have a list of class objects where one of the class properties is a <code>List&lt;string&gt;</code> containing miscellaneous values. I need to write a LINQ query to return the class objects containing a certain value within the <code>List&lt;string&gt;</code> property.</p>
  
  <p>Here's an example class...</p>
  
  <pre><code>public class Item
  {
      public string Name { get; set; }
      public int ID { get; set; }
      public List&lt;string&gt; Attributes { get; set; }
  }
  </code></pre>
  
  <p>And here's an example of some data and a method that filters based on a specified attribute value:</p>
  
  <pre><code>public class Info
  {
      public List&lt;Item&gt; GetItemInfo(string Attribute = null)
      {
          List&lt;Item&gt; itemList = new List&lt;Item&gt;
          {
              new Item { Name = "Wrench",  ID = 0, Attributes = new List&lt;string&gt; { "Tool"  } },
              new Item { Name = "Pear",    ID = 1, Attributes = new List&lt;string&gt; { "Fruit" } },
              new Item { Name = "Apple",   ID = 2, Attributes = new List&lt;string&gt; { "Fruit" } },
              new Item { Name = "Drill",   ID = 3, Attributes = new List&lt;string&gt; { "Tool",   "Power"  } },
              new Item { Name = "Bear",    ID = 4, Attributes = new List&lt;string&gt; { "Animal", "Mammal" } },
              new Item { Name = "Shark",   ID = 5, Attributes = new List&lt;string&gt; { "Animal", "Fish"   } }
          };
  
          // If no Attribute specified, return the entire item list
          if (Attribute == null) return itemList;
  
          // Otherwise, filter by the Attribute specified
          else return  ?????
      }
  }
  </code></pre>
  
  <p>A call to the <code>GetItemInfo</code> method would return this:</p>
  
  <p><code>myInfo.GetItemInfo("Tool")</code> should return the Items with names "Wrench" and "Drill"</p>
  
  <p><code>myInfo.GetItemInfo("Power")</code> should return only the Item with name "Drill"</p>
  
  <p><code>myInfo.GetItemInfo("Fruit")</code> should return the Items with names "Pear" and "Apple"</p>
  
  <p>Easy enough to write a LINQ expression with a sub-query. In this case, however, because the <code>List&lt;string&gt;</code> has no column name to reference, I'm struggling with how to write this expression.</p>