473,371 Members | 1,448 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,371 software developers and data experts.

object projection

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
Jan 18 '06 #1
5 2149
Adam Wawrzyniak wrote:
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?


You need to cast:

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

Jon

Jan 18 '06 #2
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
Jan 18 '06 #3
Thanks
Adam

"Marc Gravell" <mg******@rm.com> schrieb im Newsbeitrag
news:eL**************@TK2MSFTNGP15.phx.gbl...
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

Jan 18 '06 #4
Marc Gravell wrote:
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

Jan 18 '06 #5
<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

Jan 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ajith Prasad | last post by:
I would appreciate advice on how best to formulate the following problem in Python. I have originally posted the problem to the J Programming forum and received a one-line formulation ((#s)...
1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
1
by: anirbanab | last post by:
Hi, I am trying to take a parallel projection of a real-life surface(fractal surface) on series of 2D planes(that is X-Y, Y-Z, Z-X planes). The idea then is to concentrate on any particular patch...
0
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What...
0
by: freshman | last post by:
# test code: http://pyode.sourceforge.net/tutorials/tutorial3.html # #i want selecting object in pyode test code. # what's wrong? # under modify code # see selectObject() function # pyODE...
0
by: Garmt de Vries-Uiterweerd | last post by:
X-posted to opera.page-authoring, because this is a bit Opera-specific for the moment. F'up to ciwas. I am playing around with dedicated styling for the projection media type.. Currently the...
5
by: TommyC | last post by:
Hi all, Do anyone of u know how to write the codes for horizontal and vertical integral projection in C? I decide to use this method for automated mouth detection. Any helps will be apprecated. ...
3
by: dariosalvi78 | last post by:
Hi, I am exploring the object-relational mapping tools (the free ones) for the .net CF 2. As far as I have seen all the tools start from the tables of a database and generate code to build...
4
by: xiao | last post by:
Can anyone give some link about the link projection in C? Thank you :) I am trying to adjust the data in a map, Thank you :)
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.