title: Change style of output with LINQ, GroupBy
body: <p>I have this <a href="https://dotnetfiddle.net/PAcgWg" rel="nofollow noreferrer">DotNetFiddle</a>.</p>
  
  <p>Code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  
  public class Program
  {
      public static void Main()
      {       
          // create Questions
  
          var questionOne = new Question(){QuestionId = 1, ActualQuestion = "Who"};
          var questionTwo = new Question(){QuestionId = 2, ActualQuestion = "What"};
          var questionThree = new Question(){QuestionId = 3, ActualQuestion = "Where"};
  
          // Assign questions to the specified list of questions
  
          var applicationOneQuestions = new List&lt;Question&gt;(){questionOne, questionTwo, questionThree};
          var applicationTwoQuestions = new List&lt;Question&gt;() {questionOne, questionTwo};
          var applicationThreeQuestions = new List&lt;Question&gt;() {questionOne, questionThree};
          var applicationFourQuestions = new List&lt;Question&gt;() {questionOne};
  
          // Create Applications
  
          var applicationOne = new Application(){AppId = 1, Questions = applicationOneQuestions};
          var applicationTwo = new Application(){AppId = 2, Questions = applicationTwoQuestions};
          var applicationThree = new Application() {AppId = 3, Questions = applicationThreeQuestions};
          var applicationFour = new Application() {AppId = 4, Questions = applicationFourQuestions};
  
          // Create List of Applications
  
          var lstApplications = new List&lt;Application&gt;(){applicationOne, applicationTwo, applicationThree, applicationFour};
  
          // Group Applications based on Questions
  
          var groupApplications = lstApplications.GroupBy(x =&gt; x.Questions).Select(t =&gt; new Section { AppIds = t.Select(z =&gt; z.AppId).ToList() , Questions = t.Key}).ToList();
  
          foreach(var item in groupApplications)
          {
              foreach(var appId in item.AppIds)
              {
                  Console.WriteLine(appId);
  
              }
  
              foreach(var question in item.Questions)
              {
                  Console.WriteLine(question.ActualQuestion);
              }
  
              Console.WriteLine("\n");
          }
      }
  }
  
  public class Application
      {
          public int AppId { get; set; }
          public List&lt;Question&gt; Questions { get; set; }
      }
  
  public class Section
         {
              public List&lt;int&gt; AppIds { get; set; }
              public List&lt;Question&gt; Questions { get; set; }
          }
  
  public class Question
  {
      public int QuestionId {get;set;}
      public string ActualQuestion {get;set;} 
  }
  </code></pre>
  
  <p>Once you run the program, you get an output like so:</p>
  
  <pre><code>1
  Who
  What
  Where
  
  
  2
  Who
  What
  
  
  3
  Who
  Where
  
  
  4
  Who
  </code></pre>
  
  <p>Now, I would like to change the output to look like this:</p>
  
  <pre><code>A1, A2, A3, A4 - Who
  A1, A2 - What
  A1, A3 - Where
  </code></pre>
  
  <p>Basically, </p>
  
  <ul>
  <li>application 1,2,3,4 all contain question 1 - who</li>
  <li>application 1, 2 contain question 2 - what</li>
  <li>application 1, 3 contain question 3 - where</li>
  </ul>
  
  <p>How do I achieve this output?</p>