Public class RMB {public int yuan = 0; Public RMB (INT yuan) {yuan = yuan;} public static RMB operator + (RMB Rmb1, RMB RMB2) {// type return new RMB (rmb1.yuan + rmb2.yuan);} public static implicit operator int (RMB) {// type 2: Implicit implements forced type conversion return RMB. yuan;} public static implicit operator RMB (INT yuan) {// three types: Implicit implements forced type conversion return new RMB (yuan );} public static explicit operator RMB (float yuan) {// type 4: explicit implements implicit type conversion. A forced type conversion is required externally. Return new RMB (INT) yuan );}}
Call
RMB RMB1 = new RMB (1); RMB RMB2 = new RMB (2); RMB RMB3 = RMB1 + RMB2; // a single int yuan = RMB3; // RMB RMB4 = 5; // three types: Implicit implements forced type conversion RMB RMB5 = (RMB) 5f; // four types: explicit implements implicit type conversion and requires forced type conversion outside