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;
原文地址:https://www.cnblogs.com/Benjamin/p/3309983.html