code_junkie

Variable declaration in c# switch statement

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. switch (Type)
  2. {
  3. case Type.A:
  4. string variable = "x";
  5. break;
  6. case Type.B:
  7. string variable = "y";
  8. break;
  9. }
  10.  
  11. switch (Type)
  12. {
  13. case Type.A:
  14. {
  15. string variable = "x";
  16. /* do other stuff with variable */
  17. }
  18. break;
  19.  
  20. case Type.B:
  21. {
  22. string variable = "y";
  23. /* do other stuff with variable */
  24. }
  25. break;
  26.  
  27. }
  28.  
  29. switch (Type)
  30. {
  31. string variable;
  32.  
  33. case Type.A:
  34. variable = "x";
  35. break;
  36. case Type.B:
  37. variable = "y";
  38. break;
  39. }
Add Comment
Please, Sign In to add comment