我想为几种类型(如long,TimeSpan和DateTime)提供通用函数。使用基于typeof内部通用函数的特定类型
public static T Parse<T>(string text)
{
T store;
if(typeof(T) == typeof(TimeSpan)
store = (T)((object) new TimeSpan(0, 1, 0));
else
{
T.tryParse(text, out store);
}
return store;
}
有没有比双T /物体表演更好的方法?
t.tryParse不能编译,我该怎么做到类似的东西?
什么是编译错误? – Ucodia 2009-11-04 11:01:48