Reference type?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jesper Denmark

    #1

    Reference type?

    Hi,

    I'm using a very nice implementation of complex numbers
    (by Ben Houston). There is a thing that is a bit unclear
    though, why does the code in the main section below work
    without creating the object with 'new'. Who is allocating
    foo on the heap. What is hidded?, does it have anything
    to do with the fact that it implements ICloneable.


    or


    code snippet:

    static public Complex FromRealImagina ry( double real,
    double imaginary )
    {
    Complex c;
    c.Re = (double) real;
    c.Im = (double) imaginary;
    return c;
    }


    main
    {
    Complex foo;
    foo = Complex.FromRea lImaginary(2,2) ;
    Console.Writeli ne(foo);
    }
  • Daniel O'Connell

    #2
    Re: Reference type?

    Complex is a structure, allocated on the stack implictly.
    "Jesper Denmark" <jeodni@hotmail .com> wrote in message
    news:027301c390 ac$aee03610$a00 1280a@phx.gbl.. .[color=blue]
    > Hi,
    >
    > I'm using a very nice implementation of complex numbers
    > (by Ben Houston). There is a thing that is a bit unclear
    > though, why does the code in the main section below work
    > without creating the object with 'new'. Who is allocating
    > foo on the heap. What is hidded?, does it have anything
    > to do with the fact that it implements ICloneable.
    >
    > http://www.csharphelp.com/archives/archive284.html
    > or
    > http://www.codeproject.com/csharp/exocortex.asp
    >
    > code snippet:
    >
    > static public Complex FromRealImagina ry( double real,
    > double imaginary )
    > {
    > Complex c;
    > c.Re = (double) real;
    > c.Im = (double) imaginary;
    > return c;
    > }
    >
    >
    > main
    > {
    > Complex foo;
    > foo = Complex.FromRea lImaginary(2,2) ;
    > Console.Writeli ne(foo);
    > }[/color]


    Comment

    Working...