110,552
社区成员
发帖
与我相关
我的任务
分享
class Base
{
}
class A : Base
{
public int P1 { get; set; }
}
class B: Base
{
public int P2 { get; set; }
}
class Program
{
public int SomeMethod(Base obj)
{
if (obj is A) return ((A)obj).P1;
else if (obj is B) return ((B)obj).P2;
else
throw new NotImplementedException("你很蛋疼");
}
}
楼主你确定这是你想要的吗?