static void Main(string[] args) { List<carowner> owners = new List<carowner>() { new CarOwner(){Name="Hari", Gender="Male",Age=23, Cars= new List<car>(){new Car(){Name="Ambassador", Type="Heavy"},new Car(){Name="Maruti", Type="Light"}}}, new CarOwner(){Name="Ruchira", Gender="Female",Age=18, Cars= new List<car>(){new Car(){Name="Sumo", Type="Heavy"}}}, new CarOwner(){Name="Shyam", Gender="Male",Age=45, Cars= new List<car>() }, new CarOwner(){Name="Rakesh", Gender="Male",Age=40, Cars= new List<car>(){new Car(){Name="Renault", Type="Heavy"},new Car(){Name="Pageiro", Type="Heavy"}}}, new CarOwner(){Name="Sarmistha", Gender="Female",Age=40, Cars= new List<car>(){new Car(){Name="Innova", Type="Heavy"},new Car(){Name="Maruti", Type="Light"},new Car(){Name="Eon",Type="Light"},new Car(){Name="Jeep",Type=""}}}, new CarOwner(){Name="Aliah", Gender="Female",Age=64, Cars= new List<car>(){new Car(){Name="Bolero", Type="Heavy"},new Car(){Name="Hyundai", Type="Light"}}}, }; var results = owners.GroupBy(o => o.Gender, o => o.Cars, (key, g) => new { Gender = key, Name = g.SelectMany(cars => cars) .Select(car => car.Name).Distinct().OrderBy(k => k).ToList() }); foreach (var result in results) { Console.Write(result.Gender + ": " + string.Join(", ", result.Name.ToArray())); Console.WriteLine(); } Console.ReadLine(); }
Mode=TwoWay
Command="{Binding CheckCommand, Mode=TwoWay}"