Re: Reference Types and Value Types
From: Lateralus [MCAD] (dnorm252_at_yahoo.com)
Date: 09/03/04
- Next message: Yoshi: "Re: xp sp2 download problem"
- Previous message: CaptainKS: "Setting the ClassName for a standalone app?"
- In reply to: daniel: "Re: Reference Types and Value Types"
- Next in thread: Jon Skeet [C# MVP]: "Re: Reference Types and Value Types"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 2 Sep 2004 20:55:48 -0500
daniel,
That is correct. There is only one storage location of the object. The
variables all just point to the same object.
--
Lateralus [MCAD]
"daniel" <user@example.com> wrote in message
news:OfNECeTkEHA.3724@TK2MSFTNGP11.phx.gbl...
> Ahh, thank you Lateralus for the quick reply. I have a quick follow up
> question, though:
>
> If a reference type is always passed by reference, then (while stupid and
> messy):
>
> <code>
> // with a return type this time!
> void func1()
> {
> SomeType myType = new myType();
> func2(myType);
> }
> void func2(SomeType myType)
> {
> func3(mytype);
> }
> void func3(SomeType myType)
> {
> Console.Write(myType.ToString());
> }
> </code>
>
> will not cause a substantial amount of increased overhead at all (other
> than variables on the stack), because only one object is every created.
>
>
> Thanks,
> -daniel
>
>
>
> Lateralus [MCAD] wrote:
>
>> daniel,
>> To my knowledge you can't pass a "reference" type by value if you
>> wanted to. It is automatically passed by reference. If you have a value
>> type and you want to maintain it's value across method calls, you need to
>> pass it by reference.
>>
>> example should print out 12:
>>
>> private void Test()
>> {
>> int index = 0;
>> Test2(ref index);
>> Console.Write(index.ToString());
>> }
>>
>> private void Test2(ref index)
>> {
>> index = 12;
>> }
>>
- Next message: Yoshi: "Re: xp sp2 download problem"
- Previous message: CaptainKS: "Setting the ClassName for a standalone app?"
- In reply to: daniel: "Re: Reference Types and Value Types"
- Next in thread: Jon Skeet [C# MVP]: "Re: Reference Types and Value Types"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|