using System;
public class Test
{
private class Wrap<T> where T : struct
{
public T Value;
public static implicit operator Wrap<T>(T v) { return new Wrap<T> { Value = v }; }
public static implicit operator T(Wrap<T> w) { return w.Value; }
public override string ToString() { return Value.ToString(); }
public override int GetHashCode() { return Value.GetHashCode(); }
// TODO other delegating operators/overloads
}
private static void assign(ref int i)
{
i = 42;
}
public static void Main()
{
Wrap<int> element = 7;
var vars = new Wrap<int>[] {1, 2, element, 3, 4};
Console.WriteLine(vars[2]);
assign(ref vars[2].Value);
Console.WriteLine(element);
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewogICAgcHJpdmF0ZSBjbGFzcyBXcmFwPFQ+IHdoZXJlIFQgOiBzdHJ1Y3QKICAgIHsKICAgICAgICBwdWJsaWMgVCBWYWx1ZTsKCiAgICAgICAgcHVibGljIHN0YXRpYyBpbXBsaWNpdCBvcGVyYXRvciBXcmFwPFQ+KFQgdikgeyByZXR1cm4gbmV3IFdyYXA8VD4geyBWYWx1ZSA9IHYgfTsgfQogICAgICAgIHB1YmxpYyBzdGF0aWMgaW1wbGljaXQgb3BlcmF0b3IgVChXcmFwPFQ+IHcpIHsgcmV0dXJuIHcuVmFsdWU7IH0KCiAgICAgICAgcHVibGljIG92ZXJyaWRlIHN0cmluZyBUb1N0cmluZygpIHsgcmV0dXJuIFZhbHVlLlRvU3RyaW5nKCk7IH0KICAgICAgICBwdWJsaWMgb3ZlcnJpZGUgaW50IEdldEhhc2hDb2RlKCkgeyByZXR1cm4gVmFsdWUuR2V0SGFzaENvZGUoKTsgfQogICAgICAgIC8vIFRPRE8gb3RoZXIgZGVsZWdhdGluZyBvcGVyYXRvcnMvb3ZlcmxvYWRzCiAgICB9CgogICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBhc3NpZ24ocmVmIGludCBpKQogICAgewogICAgICAgIGkgPSA0MjsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICB7CiAgICAgICAgV3JhcDxpbnQ+IGVsZW1lbnQgPSA3OwogICAgICAgIHZhciB2YXJzID0gbmV3IFdyYXA8aW50PltdIHsxLCAyLCBlbGVtZW50LCAzLCA0fTsKICAgICAgICBDb25zb2xlLldyaXRlTGluZSh2YXJzWzJdKTsKICAgICAgICBhc3NpZ24ocmVmIHZhcnNbMl0uVmFsdWUpOwogICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKGVsZW1lbnQpOwogICAgfQp9