C# 泛型隐式转换

 public class State<T>  
    {
        private T _value;
        public T Value
        {
            get { return _value; }
            set
            { 
                _value = value;
            }
        }

        //隐式转换
        public static implicit operator State<T>(T input)
        {
            return new State<T>() { _value = input };
        }

        public override string ToString()
        {
            return _value.ToString();
        }


        //显式转换
        //public static explicit operator State<T>(T input)
        //{
        //    return new State<T>() { _value = input };
        //}
}
 public State<int> Count2 { get; set; } = 1; 
上一篇:如何在JavaScript中检测字母字符?


下一篇:Java0基础教程——java的安装