explicit-conversion

When should I define a (explicit or implicit) conversion operator in C#?

淺唱寂寞╮ 提交于 2019-11-27 17:58:57
问题 A somewhat little-known feature of C# is the possibility to create implicit or explicit user-defined type conversions. I have been writing C# code for 6 years now, and I have never used it. So, I'm afraid I might be missing good opportunities. What are legitimate, good uses of user-defined conversions? Do you have examples where they are better than just defining a custom method? -- Turns out, Microsoft has some design guidelines about conversions, the most relevant of which is: Do not