Redundancy in the following code - C#