- using System;
- using System.Linq;
- using System.Xml.Linq;
- namespace ForgetCode
- {
- public class MainClass
- {
- public static void Main()
- {
- dat customers = new dat(@"c:\data.mdf");
- // queryCustomersByCity is an IEnumerable<IGrouping<string, Customer>>
- var queryCustomersByCity =
- from cust in customers
- group cust by cust.City;
- // customerGroup is an IGrouping<string, Customer>
- foreach (var customerGroup in queryCustomersByCity)
- {
- Console.WriteLine(customerGroup.Key);
- foreach (Customer customer in customerGroup)
- {
- Console.WriteLine(" {0}", customer.Name);
- }
- }
- }
- }
- }