RE: Passing arguements by reference
- From: "David Anton" <DavidAnton@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 26 Feb 2006 10:23:26 -0800
You never pass actual objects, but references to those objects.
When you pass a reference to an object by 'ref', you are passing the actual
reference to the object - this reference can be changed by the method upon
return.
When you pass a reference to an object by value, you are passing a copy of
the reference to the object - this reference cannot be changed by the method
upon return.
For both cases, the method can manipulate and change the internals of the
object, since a reference and a copy of a reference point to the same object.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
"Andrew Bullock" wrote:
Hi,.
I have two classes, A and B,
B takes an A as an argument in its constructor:
A a1 = new A();
B b = new B(a1);
///
A a2;
public B(A aa)
{
a2 = aa;
}
However, I figured that I could reduce memory usage and increase
performance by passing aa by reference.
How do I alter my code to do this?
I know I need to do this:
public B(ref A aa)
but how do i declare a2? If i leave it as it is, does that mean a1 and
a2 both point to the same memory location, or when assigning a2 is the
object copied?
Thanks
Andrew
- References:
- Passing arguements by reference
- From: Andrew Bullock
- Passing arguements by reference
- Prev by Date: Re: Passing arguements by reference
- Next by Date: Re: Accessible object from any form
- Previous by thread: Re: Passing arguements by reference
- Next by thread: Adding an icon to Listview items
- Index(es):
Relevant Pages
|
|