Q:

Grouping the same object according to the elements of their lists

I have following list of the objects of type Application, which looks like:  
public class Application
    {
        public int AppId { get; set; }
        public List<Question> Questions { get; set; }
    }

What I want to do is to map them to object of type Section looking like:   
public class Section
       {
            public List<int> AppIds { get; set; }
            public List<Question> Questions { get; set; }
        }

by grouping them according to following rule: gather all the same questions under the lists of AppIds, which contain these questions.  Exemplary Input and Output:
Input: A1(Q1,Q2,Q3), A2(Q1,Q2), A3(Q1,Q3), A4(Q1).  
Output: A1,A2,A3,A4(Q1), A1,A2(Q2), A1,A3(Q3)

Is that possible to do it in LINQ?  Or I have to write logic on my own? 

A:

Maybe there is a simpler way, but this is the first LINQ query I wrote and should be enough to at least get you started.  First I flattened out your questions and appids, then I regrouped by questions and listed your appids by question instead.  Note that you'll have to populate your List of applications before this will run. 
List<Application> app = new List<Application>();
var output = (from a in app. SelectMany(p => p.Questions. Select(z => new {z, p.AppId})
group a.AppId by new 
{
a.Questions
} into combined
select new 
{
combined. Key. Questions,
combined. ToList()
});

