fork download
  1. using System;
  2.  
  3. class OnlyOneOption
  4. {
  5. // Constructor is private so users cannot create their own instances.
  6. private OnlyOneOption() {}
  7.  
  8. private static int LastID = 0;
  9. private readonly int id = ++OnlyOneOption.LastID;
  10. static public implicit operator int(OnlyOneOption option) { return option.id; }
  11.  
  12. public static OnlyOneOption OptionA = new OnlyOneOption();
  13. public static OnlyOneOption OptionB = new OnlyOneOption();
  14. public static OnlyOneOption OptionC = new OnlyOneOption();
  15. }
  16.  
  17. public class Test
  18. {
  19. public static void Main()
  20. {
  21. OnlyOneOption option = OnlyOneOption.OptionA;
  22. switch(option) {
  23. case OnlyOneOption.OptionA: break;
  24. case OnlyOneOption.OptionB: break;
  25. default: throw new InvalidOperationException();
  26. }
  27. }
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(23,24): error CS0150: A constant value is expected
prog.cs(24,24): error CS0150: A constant value is expected
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty