Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a sample. Hope it clarifies everything:</p> <pre><code>static void MethodRun() { List&lt;Topping&gt; testToppings = new List&lt;Topping&gt; { Topping.Cheese, Topping.Pepperoni, Topping.Sausage }; var firstLetterofToppings = testToppings.Select(top =&gt; top.ToString().First()); // returns "C, P, S" var singleToppingPizzas = testToppings.Select(top =&gt; new Pizza(top)).ToArray(); // returns "Pizza(Cheese), Pizza(Pepperoni), Pizza(Sausage)" List&lt;Topping&gt; firstPizza = new List&lt;Topping&gt; { Topping.Cheese, Topping.Anchovies }; List&lt;Topping&gt; secondPizza = new List&lt;Topping&gt; { Topping.Sausage, Topping.CanadianBacon, Topping.Pepperoni }; List&lt;Topping&gt; thirdPizza = new List&lt;Topping&gt; { Topping.Ham, Topping.Pepperoni }; List&lt;IEnumerable&lt;Topping&gt;&gt; toppingsPurchaseOrder = new List&lt;IEnumerable&lt;Topping&gt;&gt; { firstPizza, secondPizza, thirdPizza }; var toppingsToOrder = toppingsPurchaseOrder.SelectMany(order =&gt; order); //returns "Cheese, Anchovies, Sausage, CanadianBacon, Pepperoni, Ham, Pepperoni" } class Pizza { public List&lt;Topping&gt; Toppings { get; private set; } public Pizza(Topping topping) : this(new List&lt;Topping&gt; { topping }) { } public Pizza(IEnumerable&lt;Topping&gt; toppings) { this.Toppings = new List&lt;Topping&gt;(); this.Toppings.AddRange(toppings); } } enum Topping { Cheese, Pepperoni, Anchovies, Sausage, Ham, CanadianBacon } </code></pre> <p>The key is that Select() can select any type of object. It's true that you can select a property of whatever generic value is assigned to your collection, but you can select any other type of object also. SelectMany() just flattens your list.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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