I want to find the sum of values without using a nested foreach loop
How do I write this using Linq instead?
decimal posVal = 0;
decimal negVal = 0;
foreach (var j in journal)
{
foreach (var t in j.trans)
{
foreach (var l in t.line)
{
if (l.val > 0)
posVal += l.val;
else
negVal += l.val;
}
}
}
foreach (var l in journal.SelectMany(j => j.trans).SelectMany(t => t.line)) { .. }?