public class Example
{
public static void Main()
{
Console.Write("<< Enumerable.ToLookup 출력 예제 >> \n");
List<Production> productions =
new List<Production> { new Production { Company = "A.Soft", Weight = 15.2, PhoneNumber = 0415236987 },
new Production { Company = "B.Soft", Weight = 28.7, PhoneNumber = 021534789 },
new Production { Company = "C.Soft", Weight = 8.0, PhoneNumber = 0651234569 },
new Production { Company = "D.Soft", Weight = 12.3, PhoneNumber = 0140253698 },
new Production { Company = "E.Soft", Weight = 15.8, PhoneNumber = 0854712586 } };
ILookup<char, string> lookup =
productions.ToLookup(p => p.Company[0], p => p.Company + " " + p.PhoneNumber);
foreach (IGrouping<char, string> productGroup in lookup)
{
Console.WriteLine(productGroup.Key);
foreach (string str in productGroup)
Console.WriteLine(" {0}", str);
}
Console.WriteLine(System.Environment.NewLine);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
class Production
{
public string Company { get; set; }
public double Weight { get; set; }
public long PhoneNumber { get; set; }
}