Why does this implicit type conversion in C# fail?

I believe it's because IX is an interface. The compiler thinks that maybe a value of type IX could already be derived from Wrapped Of(T item) { return new Wrapped(item); } Then you can just write: using (Wrapped wrappedIX = Wrapped. Of(plainIX)) Basically conversions can be a bit tricky for various reasons - simple methods are generally easier to understand, IMO.

I believe it's because IX is an interface. The compiler thinks that maybe a value of type IX could already be derived from Wrapped (even if Wrapped is sealed) so it doesn't use the conversion. The details are quite complicated, in sections 6.4.3 and 6.4.4 of the C# 3.0 spec.

Basically because IX is an interface, it's not "encompassed by" any types, which means a later step in 6.4.4 fails. I suggest you create a non-generic type Wrapped with this method: public static Wrapped Of(T item) { return new Wrapped(item); } Then you can just write: using (Wrapped wrappedIX = Wrapped. Of(plainIX)) Basically conversions can be a bit tricky for various reasons - simple methods are generally easier to understand, IMO.

– Dykam Mar 26 '10 at 19:31 @Dykam: You're assuming that T can be used covariantly. I'm also not sure what you mean by "this" - but as the type of plainIX is IX rather than X, I don't believe the original code would work out of the box. – Jon Skeet Mar 26 '10 at 19:39 Hmm, indeed.

Then I missed that part. Implicit conversions get messy quickly in any case. – Dykam Mar 26 '10 at 20:17.

This implicit type conversion in c fails c # because (without quotes):.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions