using System.Collections.Generic;
public static void Main(string[] args)
var productAId = Guid.NewGuid();
var productBId = Guid.NewGuid();
var customers = new List<Customer>
new Customer {Id = Guid.NewGuid(), Gender="F", LastName = "Adams", Age = 50, ProductId=productAId},
new Customer {Id = Guid.NewGuid(), Gender="M", LastName = "Jones", Age = 10, ProductId=productAId},
new Customer {Id = Guid.NewGuid(), Gender="M", LastName = "Hills", Age = 17, ProductId=productBId},
new Customer {Id = Guid.Empty, LastName = string.Empty, Age = 0},
new Customer {Id = Guid.NewGuid(), Gender="F", LastName = "Smith", Age = 15, ProductId=productAId}
var products = new List<Product>
new Product {Id = productBId, Name="ProdB", Description = "Product B"},
new Product {Id = productAId, Name="ProdA", Description = "Product B"}
var coreDemographic = customers.Where(x=>x.ProductId.HasValue && x.Age<18 && x.Id!=Guid.Empty).OrderBy(x => x.Gender).ThenByDescending(c=>c.LastName).ToList();
string femaleLastNames = string.Empty;
string maleLastNames = string.Empty;
foreach (var c in coreDemographic)
if (String.IsNullOrEmpty(femaleLastNames))
femaleLastNames = femaleLastNames + c.LastName + ",";
else if (c.Gender == "M")
if (String.IsNullOrEmpty(maleLastNames))
maleLastNames = maleLastNames + c.LastName + ",";
femaleLastNames = femaleLastNames.Remove(femaleLastNames.Length - 1);
maleLastNames = maleLastNames.Remove(maleLastNames.Length - 1);
Console.WriteLine(femaleLastNames);
Console.WriteLine(maleLastNames);
public Guid Id { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string Gender {get; set;}
public Guid? ProductId {get; set;}
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }