Sum property based on existance in list and quantity

Viewed 55

I am currently summing the value of the SIZE property of my Object based on the existence of its NAME in my list SOURCEFIELDS (see code).

string[] SourceFields = MergeParameters
  .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

int OverallLength = MainFields
  .FindAll(FO => SourceFields
     .Any(List => FO.Name.Equals(List)))
  .Sum(FO => FO.Size);

My issue is, if a value appears in SOURCEFIELDS twice (which is possible), I need the value to be doubled (or however many times it appears).

Is this possible with a linq query? I would like to avoid nested loops if possible.

2 Answers
Related