Multiple implicit conversions on custom types not allowed?

There is no multi-step user-defined implicit conversion. int -> bool -> A is allowed because the int->bool conversion isn’t user-defined. 12.3 Conversions [class.conv] 1 Type conversions of class objects can be specified by constructors and by conversion functions. These conversions are called user-defined conversions and are used for implicit type conversions (clause 4), for initialization … Read more

Integer conversions(narrowing, widening), undefined behaviour

An integral conversion never produces undefined behaviour (it can produce implementation-defined behaviour). A conversion to a type that can represent the value being converted is always well-defined: the value simply stays unchanged. A conversion to an unsigned type is always well-defined: the value is taken modulo UINT_MAX+1 (or whatever maximum value the target type admits). … Read more

Can we define implicit conversions of enums in c#?

There is a solution. Consider the following: public sealed class AccountStatus { public static readonly AccountStatus Open = new AccountStatus(1); public static readonly AccountStatus Closed = new AccountStatus(2); public static readonly SortedList<byte, AccountStatus> Values = new SortedList<byte, AccountStatus>(); private readonly byte Value; private AccountStatus(byte value) { this.Value = value; Values.Add(value, this); } public static implicit … Read more