Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing Objects

Posted on 2004-08-31
1
Medium Priority
?
194 Views
Last Modified: 2010-04-15
HI All,

This is a simple question, i m confused about.

I am passing an object from one class to another like,

Class1.cs

\\ Make Object of Class3 - suppose obj3
\\ Call Class2 passing object of Class3

Class2 secondClass = new Class2(obj3);


Now in Class2.cs constructor

private Class3 objof3;

Class2(Class3 anObject)
{
objof3 = anObject;
// Some Stuff
}

I want to use the object values of anObject throughout my Class2 class.
So, i am making private object of class3 in Class2 itself. and assign that objof3 to the anObject object.

Now the question is,
If i am assigning it this way, then will objof3 will contain the reference to the anObject object, or it will copy everything in a new memory location.

as far as i know, objects are reference types, and so it will take only the reference of the anObject class, and i will be able to use the anObject values throughout my Class2 through the objof3 object, is it right??

I just want to clear my doubt.
0
Comment
Question by:chintan_vaishya
1 Comment
 

Accepted Solution

by:
monkeymole earned 500 total points
ID: 11939726
Yes you are right with the reference model you describe. You will only store a refernce to the object in Class2. Therefore if you created multiple Class2's with the same instance of Class3 object, any changes to the instance used to create the Class2s would be seen in all the Class3's.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question