code_junkie

C# What is the best way to create an enum that is used by multiple classes

Nov 13th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. /// <summary>
  2. /// Defines the types of cars we support
  3. /// </summary>
  4. public enum CarType
  5. {
  6. /// <summary>
  7. /// VW - the peoples car
  8. /// </summary>
  9. Volkswagen,
  10.  
  11. public enum CarTypes
  12.  
  13. Volkswagen = 1,
  14.  
  15. /// <summary>
  16. /// They own lambo... can't be all that bad
  17. /// </summary>
  18. Audi = 2,
  19.  
  20. /// <summary>
  21. /// Good, cheap, reliable
  22. /// </summary>
  23. Toyota = 4,
  24.  
  25. using TotallyDifferentNameSpace.Enums;
  26.  
  27. namespace EnumEx
  28. {
  29. class Program
  30. {
  31. static void Main(string[] args)
  32. {
  33. CarType car = CarType.Audi;
  34. PetrolType pType = PetrolType.Diesel;
  35. }
  36. }
  37.  
  38. public enum CarType
  39. {
  40. Volkswagen,
  41. Audi,
  42. Toyota,
  43. Ford,
  44. Porsche,
  45. Lada
  46. }
  47. }
  48.  
  49. namespace TotallyDifferentNameSpace.Enums
  50. {
  51. public enum PetrolType
  52. {
  53. Gasoline,
  54. Diesel
  55. }
  56. }
  57.  
  58. public class A : ISomeInterface
  59. {
  60. public static readonly A Instance = new A();
  61. private A()
  62. {
  63. }
  64.  
  65. }
  66.  
  67. public class B : ISomeInterface
  68. {
  69. public static readonly B Instance = new A();
  70. private B()
  71. {
  72. }
  73. }
Add Comment
Please, Sign In to add comment