How to call x of class a from object of class b without marking x of class a as virtual.
Is it possible
public class a { public int x { get; set; } }
public class b : a { public int x { get; set; } }
public class c {
a _a = new a();
b _b = new b();
public c()
{
int y=_a.x;
y=_b.x;
_b.x = y;
}
}
base.x()should work inside thebtype (but that isn’t what you have here).In the “method hiding” scenario (what you have), it also largely depends on what a variable is typed as, so casting to
ashould work:or more succinctly: