object projection

  • Thread starter Thread starter Adam Wawrzyniak
  • Start date Start date
A

Adam Wawrzyniak

Hi,

this is my problem:
-------------------
public class Rectangle : Shape
{}
....
Shape shape;
shape = graph.AddShape(uid, pointXY);
----------------------------
AddShape returns a Shape object but in fact that is a Rectangle object, how
do I project it to this class in order to use Rectangles methods and
variables?

I got stuck; thanks for help
Adam Wawrzyniak
 
Adam said:
this is my problem:
-------------------
public class Rectangle : Shape
{}
...
Shape shape;
shape = graph.AddShape(uid, pointXY);

You need to cast:

Shape shape = (Rectangle) graph.AddShape(uid, pointXY);

Jon
 
I think that should be:

Rectangle rect = (Rectangle) graph.AddShape(uid, pointXY);

Note also that you should be pretty sure that you are expecting a Rectangle;
if not, you should look at the "is" and "as" operators on MSDN2.

Marc
 
Marc said:
I think that should be:

Rectangle rect = (Rectangle) graph.AddShape(uid, pointXY);

Sorry, yes. It's that old "shouldn't post before first cup of coffee"
problem. I'd love to say "It won't happen again" but that would be
overly optimistic...

Jon
 
<Laughs/> Very familiar with that problem; have you *seen* the amount of
times I post a chain all on my own correcting some typo!

Plus - its so rare that I get to find fault in your code that I couldn't
resist ;-p

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top