Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

learning C# ... about objects and the = oper

Name: Anonymous 2006-04-26 23:26

            Poop x = new Poop(6);
            Poop y = new Poop(123);
           
            x.Print();  // output is 6
            y.Print();  // output is 123
           
            x = y;      // was object copied from y to x?
            x.Print();  // output is 123
            y.Print();  // output is 123
           
            y.P = 5555; // well, let's see...
            x.Print();  // output is 5555 *
            y.Print();  // output is 5555
           
                        // no -- x now references same object that y is
// so objects are treated as pointers... no biggie
            //  ... but how do I use = in a "copy" kind of way?

Name: Anonymous 2006-04-27 1:44

>>1
Protip: YOU DON'T!

Name: Anonymous 2006-04-27 3:21

Implement a clone() method that constructs and returns a new object with all the fields set to the same as the object to be cloned.

Or use immutable objects to the point becomes moot. <3 immutable objects.

Name: Anonymous 2006-04-27 4:22

Like... WTF, no automatic way to copy an object?

Name: Anonymous 2006-04-27 4:56

What do you think this is, C++?

Name: Anonymous 2006-04-27 6:20

>>5
A language
It should have features
Features would include copying objects

Name: Anonymous 2006-04-27 6:48

The language can't perform an automatic, intelligent deep copy any more than C++ can.  That's why C++ requires implementation of copy constructors, and that's why C# requires implementation of a clone method or a copy constructor.

Name: Anonymous 2006-04-27 17:00

Oh lawd is dat some operator overloading

Name: Anonymous 2006-04-27 17:16

def = o
    o = self
end

Name: Anonymous 2006-04-27 18:26

>>9
Infinite recursion?

Name: Anonymous 2006-04-27 18:46

a=a

Name: Anonymous 2006-04-28 15:24

>>9
Infinately retarded?

Name: Anonymous 2006-05-02 3:28

Yeah c++ would need a deep copy explicitly written out.  Don't know c# because you fail at it

Name: Anonymous 2009-02-28 9:54

Terrible!

Name: Anonymous 2009-02-28 9:55

Terrible!

Terrible!

Terrible[i]![/i]

Name: Anonymous 2010-06-07 6:44

Hi, I can spam /prog/ too, you faggot.

Also, smoke weed everyday.

Name: Anonymous 2011-02-03 2:53

Name: Anonymous 2011-02-04 14:58

Name: Anonymous 2012-03-28 2:21

my farts burn my anus
it hurts
in a good way

Don't change these.
Name: Email:
Entire Thread Thread List