Implicit conversion/cast operators from interface types #3464
Replies: 5 comments 16 replies
-
https://stackoverflow.com/questions/2433204/why-cant-i-use-interface-with-explicit-operator
|
Beta Was this translation helpful? Give feedback.
-
Oh, well that is more than understandable. EDIT: On second thoughts, however, it is understandable when converting to an interface. |
Beta Was this translation helpful? Give feedback.
-
The recommended usage of conversion in linq is an explicit |
Beta Was this translation helpful? Give feedback.
-
That would be odd for the same reason: you just converted a thing from an interface type, yet you cannot go back to that interface? I i = ...;
C c = i;
Console.WriteLine(c is I); // Never returns false today (Assuming I is an interface) |
Beta Was this translation helpful? Give feedback.
-
I always bump into this, it's so annoying. Can we get any answer from the team as to why this can't be disabled? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
During some code developement today, I wanted to write something like this:
to allow some user code like the following:
Obviously, the code would not compile:
Aside from wanting this code to work, it got me thinking:
Why did Microsoft take this design choice at that time? What were the specific reasons? I hardly think that it was an CLR-issue, as operators get compiled to (specially named) methods in the background -- so any conversion operator invocation should work exactly like an equivalent static method invocation.
Bonus points if you are a member on the LDT and you can tell me whether the team would be open to relaxing this conversion rule/limitation.
Beta Was this translation helpful? Give feedback.
All reactions