✅ How to optimize this method? - C#