using System.Collections.Generic;
public static void Main()
List<C> Lista = new List<C>
new C { Cuenta= "1000.2.15.3", ImporteA=230, ImporteB=500 },
new C { Cuenta= "1000.2.15.4", ImporteA=100, ImporteB=30 },
new C { Cuenta= "1000.2.16.4", ImporteA=160, ImporteB=35 }
var Result = Lista.Select(r => new
CuentaPadre = C.GetCuentaPadre(r.Cuenta),
.GroupBy(x => x.CuentaPadre)
ImporteA = x.Sum(d => d.ImporteA),
ImporteB = x.Sum(d => d.ImporteB)
foreach(var resultado in Result)
Console.WriteLine("Cuenta {0} , ImporteA {1}, ImporteB {2}",resultado.CuentaPadre,resultado.ImporteA,resultado.ImporteB);
public string Cuenta { get; set; }
public int ImporteA { get; set; }
public int ImporteB { get; set; }
public static string GetCuentaPadre(string grupo)
var Splitted = grupo.Split('.');
return string.Join(".",Splitted.Take(Splitted.Count() - 1).ToArray());