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

来源:互联网 发布:宇宙外面是什么 知乎 编辑:程序博客网 时间:2024/05/20 00:49

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

例:

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


0 0
原创粉丝点击