public class Example
{
public static void Main()
{
Console.Write("<< Enumerable.ToDictionary 출력 예제 >> \n");
List<Production> productions =
new List<Production>
{ new Production { Company = "A.Soft", Weight = 45.2, PhoneNumber = 0123542145 },
new Production { Company = "B.Soft", Weight = 58.7, PhoneNumber = 0412563541 },
new Production { Company = "C.Soft", Weight = 5.0, PhoneNumber = 0632541258 },
new Production { Company = "D.Soft", Weight = 23.8, PhoneNumber = 0540210369 } };
Dictionary<long, Production> dictionary =
productions.ToDictionary(p => p.PhoneNumber);
foreach (KeyValuePair<long, Production> kvp in dictionary)
{
Console.WriteLine("Key {0}: {1}, {2}", kvp.Key, kvp.Value.Company, kvp.Value.Weight);
}
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; }
}