Beginners Question on 'return'

  • Thread starter Thread starter Martijn Mulder
  • Start date Start date
M

Martijn Mulder

I just want to be sure about this. When I have code like this:

//data member
System.Drawing.Drawing2D.GraphicsPath graphicspath=new
System.Drawing.Drawing2D.GraphicsPath();

//method
public System.Drawing.Drawing2D.GraphicsPath GetGraphicsPath()
{
return graphicspath;
}

there is a reference, a pointer returned to 'graphicspath' and NOT a copy of
the object?
 
Martijn said:
I just want to be sure about this. When I have code like this:

//data member
System.Drawing.Drawing2D.GraphicsPath graphicspath=new
System.Drawing.Drawing2D.GraphicsPath();

//method
public System.Drawing.Drawing2D.GraphicsPath GetGraphicsPath()
{
return graphicspath;
}

there is a reference, a pointer returned to 'graphicspath' and NOT a copy of
the object?

If GraphicsPath is a class, then the value returned is a reference.
If GraphicsPath is a struct, then the value returned is a shallow copy
of the data.

(I don't have the docs to hand to check which is the case, but it's
worth knowing the general principles.)

Jon
 
Hi, wot 's meaning of "shallow copy"?

Jon Skeet said:
If GraphicsPath is a class, then the value returned is a reference.
If GraphicsPath is a struct, then the value returned is a shallow copy
of the data.

(I don't have the docs to hand to check which is the case, but it's
worth knowing the general principles.)

Jon
 
HuffmaN said:
Hi, wot 's meaning of "shallow copy"?

In this context it means:
A copy of the instance fields if the struct
fields of a valuetype are copied in the same way.
fields of a referencetype are set to the same instance.
 
HuffmaN said:
Hi, wot 's meaning of "shallow copy"?

Well, how did your Google search turn out? A Google search for:
"shallow copy" .NET
gives me lots of results which look promising.

It's always worth trying a simple search before asking a question.

Jon
 
clintonG said:
Doesn't the method signature itself answer the question or indicate the
implied return type?

Well, it answers in terms of what the type is. It doesn't answer the
question as to how return values are handled, or fill in my ignorance
as to whether GraphicsPath is a struct or a class.
 
fill in my ignorance as to whether GraphicsPath is a struct or a class.


GraphicsPath is a class
 

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