score:1

The easiest way is probably to "flatten" the problem and then do the group by:

    var query = officers.SelectMany(
        x => new[] {
            new { x.Name, RO = x.ReportingOfficer1 },
            new { x.Name, RO = x.ReportingOfficer2 },
            new { x.Name, RO = x.ReportingOfficer3 }
        }
    );
    var grouped = query.GroupBy(y => y.RO);
    foreach (var group in grouped) {
        foreach (var item in group) {
            Console.WriteLine(String.Format("{0}: {1}", item.RO, item.Name));
        }
    }

Here, I am assuming officers is a IEnumerable<Officer> where

class Officer {
    public string Name { get; set; }
    public string ReportingOfficer1 { get; set; }
    public string ReportingOfficer2 { get; set; }
    public string ReportingOfficer3 { get; set; }
}

With your sample data this is my output:

John: A
John: B
Jack: A
Rob: A
Rob: C
Earl: B
Carl: B
Carl: D
Chris: C
Kenny: C
Rodney: D
Jacob: D

Related Articles