fork(3) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. private class Wrap<T> where T : struct
  6. {
  7. public T Value;
  8.  
  9. public static implicit operator Wrap<T>(T v) { return new Wrap<T> { Value = v }; }
  10. public static implicit operator T(Wrap<T> w) { return w.Value; }
  11.  
  12. public override string ToString() { return Value.ToString(); }
  13. public override int GetHashCode() { return Value.GetHashCode(); }
  14. // TODO other delegating operators/overloads
  15. }
  16.  
  17. private static void assign(ref int i)
  18. {
  19. i = 42;
  20. }
  21.  
  22. public static void Main()
  23. {
  24. Wrap<int> element = 7;
  25. var vars = new Wrap<int>[] {1, 2, element, 3, 4};
  26. Console.WriteLine(vars[2]);
  27. assign(ref vars[2].Value);
  28. Console.WriteLine(element);
  29. }
  30. }
Success #stdin #stdout 0.02s 38000KB
stdin
Standard input is empty
stdout
7
42