Just wondering if there is anyway to represent the following code in C# 3.5:
public struct Foo<T> {
public Foo(T item) {
this.Item = item;
}
public T Item { get; set; }
public static explicit operator Foo<U> ( Foo<T> a )
where U : T {
return new Foo<U>((U)a.Item)
}
}
Thanks
Conversion operators can’t be generic. From the spec section 10.10, here’s the format of a conversion-operator-declarator:
Compare this with, say, a method-header:
(Sorry about the formatting – not sure how to do it better.)
Note that the operator format doesn’t include a type parameter list or type parameter constraints.