I was wondering whether overriding conversion operators is only applicable to numeric types? If not in what instances would the implicit or explicit conversion operator be applicable to other value types or reference types. An example would be great. Thanks
I was wondering whether overriding conversion operators is only applicable to numeric types? If
Share
No – you can use any type.
For example, XAttribute has a range of conversions defined that make various conversions simple:
Another useful example is Jon’s
NonNullable<T>– this is intended to work neatly with classes while disallowing nulls. The conversion operators make it easy to use.