您的位置:首页 > 编程语言 > C#

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

2015-01-24 11:35 309 查看
直接奖泛型转为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("");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: