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:
switch(variable) { case 1: //Do something break; case 2: //Do something break; case 3: //Do something break; case 4: //Do something break; }
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:
switch(variable) { case 1: Window.Background = Image1; break; case 2: Window.Background = Image2; break; case 3: Window.Background = Image3; break; case 4: Window.Background = Image4; break; //Dummy Code }
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.

