2
我試圖實現存儲的通用可空類型的類:空類型作爲泛型參數
public class myclass<T?>
{
T? myvariable;
public T? myfunction(){
return myvariable;
}
}
雖然上面的類編譯就好了,實際使用時,提供故障:
myclass<int?> c = new myclass<int>();
int? = c.myfunction(); // does not work: implicit cast from type T? in int? not possible.
// or, assuming the variable is not null
int = c.myfunction().Value; // implicit cast from type T in int not possible.
我在做什麼錯,或者我該如何解決這個問題?
你的課不編譯。 – dtb 2010-08-01 17:10:16
而你的例子沒有意義。你想達到什麼目的? – dtb 2010-08-01 17:12:19
事實上,它不會編譯......抱歉,其他錯誤必須在語法檢查器中加以說明。 我所追求的是一個存儲可空類型的類。 (以上示例中缺少的是變量設置的部分) – Peter 2010-08-01 17:16:25