✅ How to modernize this code ? - C#