✅ How to optimize this code? - C#