title: How can I split a list vertically in n parts with LINQ
body: <p>I would like to split a list in parts, <strong>without knowing how much items I will have in that list</strong>. The question is different from those of you who wants to split a list into chunk of fixed size.</p>
  
  <pre><code>int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  </code></pre>
  
  <p>I would like the values to be <strong>splitted vertically</strong>.</p>
  
  <p>Splitted in 2 :</p>
  
  <pre><code>-------------------
  | item 1 | item 6 |
  | item 2 | item 7 |
  | item 3 | item 8 |
  | item 4 | item 9 |
  | item 5 |        |
  </code></pre>
  
  <p>Splitted in 3:</p>
  
  <pre><code>| item 1 | item 4 | item 7 |
  | item 2 | item 5 | item 8 |
  | item 3 | item 6 | item 9 |
  </code></pre>
  
  <p>Splitted in 4:</p>
  
  <pre><code>| item 1 | item 4 | item 6 | item 8 |
  | item 2 | item 5 | item 7 | item 9 |
  | item 3 |        |        |        |
  </code></pre>
  
  <p>I've found a few c# extensions that can do that but it doesn't distribute the value the way I want. Here's what I've found:</p>
  
  <pre><code>// this technic is an horizontal distribution
  public static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; Split&lt;T&gt;(this IEnumerable&lt;T&gt; list, int parts)
  {
      int i = 0;
      var splits = from item in list
                      group item by i++ % parts into part
                      select part.AsEnumerable();
      return splits;
  }
  </code></pre>
  
  <p>the result is this but my problem is that the value are <strong>distributed horizontally</strong>:</p>
  
  <pre><code>| item 1 | item 2 |
  | item 3 | item 4 |
  | item 5 | item 6 |
  | item 7 | item 8 |
  | item 9 |        |
  </code></pre>
  
  <p>or</p>
  
  <pre><code>| item 1 | item 2 | item 3 |
  | item 4 | item 5 | item 6 |
  | item 7 | item 8 | item 9 |
  </code></pre>
  
  <p>any idea how I can <strong>distribute my values vertically</strong> and have the possibility to <strong>choose the number of parts</strong> that i want?</p>
  
  <h2>In real life</h2>
  
  <p>For those of you who want to know in which situation I would like to split a list vertically, here's a screenshot of a section of my website:</p>
  
  <p><img src="https://i.stack.imgur.com/mFvFn.jpg" alt="enter image description here"></p>