nele
nele

Reputation: 19

How can I check if an object is a Rectangle or an Ellipse

How can I check if the object that is created a Rectangle or an Ellipse is in WPF?

Ellipse ellipse = new Ellipse();
Rectangle rect = new Rectangle(); 

if (rect.getType()){
    rect.Margin = new Thickness(x,y,0,0);
} else {
    ellipse.Margin = new Thickness(x, y, 0, 0);
}

Upvotes: 1

Views: 835

Answers (1)

Arcturus
Arcturus

Reputation: 27055

Using the is keyword you can check which type an object is.

if(rect is Rectangle)

Upvotes: 3

Related Questions