C#泛型
2021-05-19 11:28
标签:isp element order https image cep dex new 泛型类 (一)泛型类 我的本意是要将一个实体参数转换为泛型对象T返回,所以初次代码就写成下面这样: public static T GetObj 可是,编译器提示无法将类型转换为T,之前竟然没碰到过这个问题。查了一下资料,原来,要这么写: public class GenericTest 天杀的ms。 C#泛型 标签:isp element order https image cep dex new 泛型类 原文地址:https://www.cnblogs.com/lihuali/p/11711395.html代码public class GenericClassBase
{
T result = default(T);
if (model is T)
{
result = (T)model; //或者 result = model as T;
}
return result;
}
{
//public static T GetObj
//{
// T result = default(T);
// if (model is T)
// {
// result = (T)model; //或者 result = model as T;
// }
// return result;
//}
public static T GetObj
{
T result = default(T);
if (model is T)
{
result = (T)(object)model; //或 (T)((object)model);
}
return result;
}
}