Is it possible to write this whole loop as Linq, or at least part of it?f - C#