Solved

Passing Objects

Posted on 2004-08-31
1
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
monkeymole earned 125 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to sort columns in DataGridView 4 64
Run tasks synchronously in background thread 19 82
C# LINQ 5 45
C# DateTime Help 6 47
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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