using System.Collections.Generic;
public static void Main()
var InputData = new List<Invoice>()
new Invoice{ Vendor = "Microsoft", NumberInvoice= 10, Type= "PC", Month = "1" },
new Invoice{ Vendor = "Microsoft", NumberInvoice= 10, Type= "PC", Month = "2" },
new Invoice{ Vendor = "Microsoft", NumberInvoice= 10, Type= "Surface", Month = "1" },
new Invoice{ Vendor = "Microsoft", NumberInvoice= 20, Type= "PC", Month = "1" },
new Invoice{ Vendor = "Microsoft", NumberInvoice= 20, Type= "PC", Month = "2" },
new Invoice{ Vendor = "Microsoft", NumberInvoice= 30, Type= "Surface", Month = "1" },
new Invoice{ Vendor = "IBM", NumberInvoice= 50, Type= "Network", Month = "5" },
new Invoice{ Vendor = "IBM", NumberInvoice= 60, Type= "Graphic Card", Month = "6" }
var result = (InputData.AsEnumerable() ?? throw new InvalidOperationException())
NumberInvoice = a.Sum(x => x.NumberInvoice),
Months = a.Select(x => x.Month).Distinct().ToArray(),
foreach (var item in result)
Console.WriteLine(item.Vendor+" "+ item.NumberInvoice + " " + String.Join(",", item.Months) + " " + item.Type );
public string Vendor { get; set; }
public decimal NumberInvoice { get; set; }
public string Type { get; set; }
public string Month { get; set; }
public class GroupedInvoice
public string Vendor { get; set; }
public decimal NumberInvoice { get; set; }
public string Type { get; set; }
public string[] Months { get; set; }