Loop Optimization - C#