Hello folks, I'm an active C# & WPF developer. One of my main goal is to achieve high standards in software development. I'm 16 years old so I have a long way to go in this industry.

While I'm writing C# code I feel I'm doing something wrong,perhaps sloppy.

csharp Code:
  1. switch(variable)
  2. {
  3.   case 1:
  4.   //Do something
  5.   break;
  6.   case 2:
  7.   //Do something
  8.   break;
  9.   case 3:
  10.   //Do something
  11.   break;
  12.   case 4:
  13.   //Do something
  14.   break;
  15. }

I've encountered myself with situations where I have to process a good amount of possible scenarios within my application. I check those using switch&case statements.

But when those scenarios are similar to each other, I just copy and paste the code I wrote the first according to x scenario, and adjust it to y scenario.

and example would be:

csharp Code:
  1. switch(variable)
  2. {
  3.   case 1:
  4.   Window.Background = Image1;
  5.   break;
  6.   case 2:
  7.   Window.Background = Image2;
  8.   break;
  9.   case 3:
  10.   Window.Background = Image3;
  11.   break;
  12.   case 4:
  13.   Window.Background = Image4;
  14.   break;
  15.   //Dummy Code
  16. }

That's seems OK to me, but what if I have to process a fair amount of code within each case. I've come out with case statements containing 20 lines of code each & 8 cases.
I feel doing that is a sloppy way to solve the problem.

Could anyone advise me on this issue I've encountered myself. Also could anyone provide me with some c# best practices books or articles.

Thanks in advance.