我想爲幾種類型(如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