Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure precisely what you're looking for, but this program:</p> <pre><code> public class Building { public enum StatusType { open, closed, weird, }; public string Name { get; set; } public StatusType Status { get; set; } } public static List &lt;Building&gt; buildingList = new List&lt;Building&gt; () { new Building () { Name = "one", Status = Building.StatusType.open }, new Building () { Name = "two", Status = Building.StatusType.closed }, new Building () { Name = "three", Status = Building.StatusType.weird }, new Building () { Name = "four", Status = Building.StatusType.open }, new Building () { Name = "five", Status = Building.StatusType.closed }, new Building () { Name = "six", Status = Building.StatusType.weird }, }; static void Main (string [] args) { var statusList = new List&lt;Building.StatusType&gt; () { Building.StatusType.open, Building.StatusType.closed }; var q = from building in buildingList where statusList.Contains (building.Status) select building; foreach ( var b in q ) Console.WriteLine ("{0}: {1}", b.Name, b.Status); } </code></pre> <p>produces the expected output: </p> <pre><code>one: open two: closed four: open five: closed </code></pre> <hr> <p>This program compares a string representation of the enum and produces the same output:</p> <pre><code> public class Building { public enum StatusType { open, closed, weird, }; public string Name { get; set; } public string Status { get; set; } } public static List &lt;Building&gt; buildingList = new List&lt;Building&gt; () { new Building () { Name = "one", Status = "open" }, new Building () { Name = "two", Status = "closed" }, new Building () { Name = "three", Status = "weird" }, new Building () { Name = "four", Status = "open" }, new Building () { Name = "five", Status = "closed" }, new Building () { Name = "six", Status = "weird" }, }; static void Main (string [] args) { var statusList = new List&lt;Building.StatusType&gt; () { Building.StatusType.open, Building.StatusType.closed }; var statusStringList = statusList.ConvertAll &lt;string&gt; (st =&gt; st.ToString ()); var q = from building in buildingList where statusStringList.Contains (building.Status) select building; foreach ( var b in q ) Console.WriteLine ("{0}: {1}", b.Name, b.Status); Console.ReadKey (); } </code></pre> <hr> <p>I created this extension method to convert one IEnumerable to another, but I'm not sure how efficient it is; it may just create a list behind the scenes.</p> <pre><code>public static IEnumerable &lt;TResult&gt; ConvertEach (IEnumerable &lt;TSource&gt; sources, Func &lt;TSource,TResult&gt; convert) { foreach ( TSource source in sources ) yield return convert (source); } </code></pre> <p>Then you can change the where clause to:</p> <pre><code>where statusList.ConvertEach &lt;string&gt; (status =&gt; status.GetCharValue()). Contains (v.Status) </code></pre> <p>and skip creating the <code>List&lt;string&gt;</code> with <code>ConvertAll ()</code> at the beginning.</p>
 

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