小编noo*_*oob的帖子

是否可以进行动态的向下转换?

如何使用强运行时已知类型进行向下转换?

public class A {}

public class B : A { public int i; }

public class C
{
    B b = new B();
    A a = b;               // here upcast, and "a" still keeps link to "b"
    ((B)a).i;              // no problem it works

    Type t = b.GetType();  // BUT how to downcast with strongly runtime known type ?
    ((t)a).i;              // like here
}
Run Code Online (Sandbox Code Playgroud)

c# downcast

2
推荐指数
1
解决办法
254
查看次数

标签 统计

c# ×1

downcast ×1