Implicit/Explicit methods for casting numeric types #80768
Unanswered
LupusInferni315
asked this question in
General
Replies: 0 comments 2 replies
-
Afaict, this seems to be an API request and not something about c#. Would you like me to move his to the runtime repo? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Most classes/structs that allow conversion declare an implicit or explicit operator that allows such conversion to take place, but numeric types (which can in cases be implicitly, and can be explicitly cast) don't offer implementation in the c# representation of the data types.
Unless I'm terribly mistaken, I know that numeric conversion 'occurs' in IL, but it would be useful if .NET 'exposed' the conversion methods.
an example case where this would be helpful comes from a project I'm working on where I've created a couple methods
That last method checks which type is being converted from and which type is being converted to and manually performs the conversion, while for every other type, its a matter of getting a hold of the conversion method and invoking it. If the implementation of c# included exposed methods for numeric conversion, this code, and the other places I've seen 'magic' methods like this, wouldn't have to exist.
Beta Was this translation helpful? Give feedback.
All reactions