fork download
  1. using System;
  2.  
  3. public class Program
  4. {
  5. internal class A
  6. {
  7. public static implicit operator A(string s) { return new A { Value = s }; }
  8. public static implicit operator string(A a) { return a.Value; }
  9.  
  10. public string Value;
  11. public override string ToString() { return Value; }
  12. }
  13.  
  14. internal class B
  15. {
  16. public static implicit operator B(string s) { return new B { Value = s }; }
  17. public static implicit operator B(A a) { return new B { Value = a }; }
  18. public static implicit operator A(B b)
  19. {
  20. b.Value = "clobbered"; // darn, no semantics enforced by the language
  21. return new Random().Next().ToString("X"); // 'basically unspecified'?
  22. }
  23.  
  24. public string Value;
  25. public override string ToString() { return Value; }
  26. }
  27.  
  28. public static void Main(string[] args)
  29. {
  30. B hello = "hello";
  31. A world = hello;
  32.  
  33. Console.WriteLine("{0} {1}", hello, world);
  34. }
  35. }
Success #stdin #stdout 0.01s 38040KB
stdin
Standard input is empty
stdout
clobbered 47453F33