Beginners Question on 'return'

Discussion in 'C#' started by MartijnMulder, Sep 20, 2006.

  1. MartijnMulder

    MartijnMulder New Member

    Joined:
    Sep 20, 2006
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  2. Essial

    Essial New Member

    Joined:
    Sep 12, 2006
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    I believe it returns a copy, not the original object. Don't hold me to it but typically if you want pointers returned, you should declare the function's result as a pointer. Please note that just about any use of pointers requires you to tag the function as "unsafe" for obvious reasons. C# tends to lend itself to stability versus efficiency. Its much safer to return a copy of an object than to define a pointer across functions.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice