KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Consider the following code: class Program { public static explicit operator long(Program x) { return 47; } static int Main(string[] args) { var x = new Program(); Console.WriteLine((decimal) x); } } To my surprise, this outputs 47 ; in other words, the explicit operator long is called even though the cast is to decimal . Is there something in the C# spec that explicitly says that this should happen (if so, where exactly) or is this the result of some other rule(s) I’m missing?
Tags (comma-separated)
Save Edits
Cancel