Reduction to the base (super) type in C#
Forums:
class Shape {
public virtual string Name {
get { return "Shape"; }
}
}
class Square : Shape {
public override string Name {
get { return "Square"; }
}
}
var square = new Square();
//implicit method
Shape shape = square;
//explicit first method
shape = square as Shape;
//explicit second method
shape = (Shape)square;
var name = shape.Name;
//name is "Square"
- Log in to post comments