implicit和explicit的基本使用
class MyAge { public int Age { get; set; } public static implicit operator MyAge(int age) { return new MyAge() { Age = age }; } public static explicit operator int(MyAge myAge) { return myAge.Age; } }
MyAge myAge=new MyAge(){Age = 20}; int i = (int)myAge; MyAge myAge1 = i;