下面是代碼:爲什麼我越來越無法拈例外
interface IA
{
}
interface IC<T>
{
}
class A : IA
{
}
class CA : IC<A>
{
}
class Program
{
static void Main(string[] args)
{
IA a;
a = (IA)new A(); // <~~~ No exception here
IC<IA> ica;
ica = (IC<IA>)(new CA()); // <~~~ Runtime exception: Unable to cast object of type 'MyApp.CA' to type 'MyApp.IC`1[MyApp.IA]'.
}
}
爲什麼會收到鑄造異常的代碼的最後一行?
什麼版本的C#? – Rake36
我認爲它是4.0 – Vlad
'CA'沒有實現'IC'。 –