Accepted answer

if you don't need console.writeline(...) your code can be summarized with linq :

list<employeeteldir> teldir = (from empl in lclemployees
                               group empl by into employeegroup
                               select new employeeteldir
                                   name = employeegroup.key,
                                   phone = (from employee in employeegroup
                                           select  // the tolist() is the holy grail of the linq queries

for the inverted operation:

list<employeelocalregister> inverse = (from employeeteldir in teldir
                                       from phone in  // doing 2 from ... in ... successively corresponds to the selectmany() linq method
                                       select new employeelocalregister
                                           name =,
                                           phone = phone


the lambda way:

var teldir = lclemployees.groupby(e =>, 
                                  (n, p) => new employeeteldir 
                                              name = n, 
                                              phone = => 

Related Query

More Query from same tag