Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding lists by selecting one item from each group of an IGrouping
    primarykey
    data
    text
    <p>Lets say I have a list of movies with a set of start times</p> <pre><code>public class Show { public string Name { get; set; } public DateTime Start { get; set; } } </code></pre> <p>Movie 1 - 8:00<br> Movie 1 - 10:00<br> Movie 1 - 12:00<br> Movie 2 - 9:00<br> Movie 2 - 11:30<br> Movie 2 - 15:00<br> Movie 3 - 12:00<br> Movie 3 - 13:00</p> <p>I end up with a grouped list, with the name of the movie being the key. I want to take one time from each group and create a <code>List&lt;DateTime&gt;</code>.</p> <p>Now since there are 3 items with 8 times, I should have 18 different lists.</p> <p>8:00 - 9:00 - 12:00<br> 8:00 - 9:00 - 13:00<br> 10:00 - 9:00 - 12:00<br> etc.</p> <p>I tried just looping through the groups</p> <pre><code>foreach (var movie in movies) { foreach (var time in movie) { // Start looping through other groups and movies } } </code></pre> <p>Anyways, this is either a bad solution or I wasn't doing something right because I ended up with Lists of <code>List&lt;DateTime&gt;</code> and I had to start looping through those lists to build more lists by only taking one item from each... It was just horrible. A regular nested <code>foreach</code> won't work because then I end up with my 8:00 Movie 1 having all instances of Movie 2 &amp; 3, so I had to keep the lists separate and that just became too messy.</p> <p>Any suggestions of a better way to approach this?</p> <p><strong>Summary:</strong></p> <p>An easier way to understand it would be like this, you want to see 3 movies in a single day. You know which 3 you want to see, you don't know what times you want to see them at.</p> <p>I need a list that would present all the options. You can see this movie at this time, this one at this time...</p> <p>e.g. </p> <p>List 1 - Movie 1 - 8:00, Movie 2 - 9:00, Movie 3 - 12:00<br> List 2 - Movie 1 - 8:00, Movie 2 - 9:00, Movie 3 - 13:00<br> List 3 - Movie 1 - 8:00, Movie 2 - 11:30, Movie 3 - 12:00<br> etc.</p> <p>Order of the list does not matter.</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.
 

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