Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a subclass that inherit Ellipse class

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
{
     ...
}
like image 287
Inox Avatar asked Dec 04 '22 07:12

Inox


1 Answers

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.
}
like image 111
D Stanley Avatar answered Jan 13 '23 17:01

D Stanley