I'm new to C# language, and I am having some trouble with creating a subclass that inherits properties of some class. I'm using Visual Studio 2012 to create Windows Phone 8 apps.
I have no trouble in inheriting classes like Button or TextBox, but I can't make it inherit Ellipse class. I can inherit Shape class, from which Ellipse is derived, but can't inherit Ellipse itself.
The idea is to add some properties to the Ellipses that I create, so I can keep track of in which order the user is pressing these ellipses. I could use another class, or use Ellipse itself (and play with its already existing properties), but for learning purposes I'd like to know why I can't (or how I can) inherit Ellipse class.
public partial class Ball : Ellipse
{
...
}
You can't. Ellipse
is sealed
.
You could wrap it, but you can't inherit from it.
public class MyEllipse: Shape
{
private Ellipse _Ellipse;
// pass through overridden Shape methods/properties to the underlying Ellipse
// add custom methods/properties.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With