C# 泛型 无法将类型xx隐式转换为“T”

时间:2017-05-18 01:01:07   收藏:0   阅读:1249

原文:C# 泛型 无法将类型xx隐式转换为“T”

直接奖泛型转为T是不能转换的 要先转Object

例: 

 public static T GetValue<T>(string inValue)
        {
            if (typeof(T) == typeof(Bitmap))
            {
                return (T)(Object)new Bitmap(inValue);
            }
            else
            {
              //一般类型
                return (T)Convert.ChangeType(inValue, typeof(T));
            }
            throw new Exception("");
        }

  

原文:http://www.cnblogs.com/lonelyxmas/p/6869978.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!