Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Coming straight from VB6 (and .NET) to C#, I encountered some "logistic" problems in the way the new MS language handles objects and structs.

 

Let's suppose we have

 

cDummy dummy_obj = new cDummy(dummyparams);
cDummy dymmy_copy = null;

 

In VB, an assignment like

dummy_copy = dummy_obj

simply makes dummy_copy reference the same object referenced by dummy_obj.

 

So, my first question is:

- In c#, does the same thing happen?

 

Let's go a little further.

Suppose we have a class with a private object of class cDummy, and a property that returns this object

private cDummy dummy_obj;

public property GetObject
{
   get
   {
       return dummy_obj;
   }
}

 

- Does the property returns a COPY of the object or a REFERENCE to the object?

If I do:

cDummy dummy_copy;
dummy_copy = dummyclass.GetObject;

does dummy_copy hold a copy of the object in dummyclass OR a reference to the same object?

 

And WHY I can't pass "byref dummyclass.GetObject" to functions?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...