fork download
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. double doub = 15.7;
  6. Foo a = doub; //error
  7. }
  8. }
  9.  
  10. struct Foo
  11. {
  12. public int value;
  13. public static implicit operator Foo(int val)
  14. {
  15. return new Foo { value = val };
  16. }
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(6,21): error CS0266: Cannot implicitly convert type `double' to `Foo'. An explicit conversion exists (are you missing a cast?)
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty