Re: Reference Types and Value Types
From: daniel (user_at_example.com)
Date: 09/02/04
- Next message: Yogi_Bear_79: "Help--My Array is too Big-----Help move to a .dat file?"
- Previous message: Juan: "Re: how to get number of rows returned by a SqlDataReader?"
- In reply to: Lateralus [MCAD]: "Re: Reference Types and Value Types"
- Next in thread: Lateralus [MCAD]: "Re: Reference Types and Value Types"
- Reply: Lateralus [MCAD]: "Re: Reference Types and Value Types"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 02 Sep 2004 16:57:29 -0500
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: Yogi_Bear_79: "Help--My Array is too Big-----Help move to a .dat file?"
- Previous message: Juan: "Re: how to get number of rows returned by a SqlDataReader?"
- In reply to: Lateralus [MCAD]: "Re: Reference Types and Value Types"
- Next in thread: Lateralus [MCAD]: "Re: Reference Types and Value Types"
- Reply: Lateralus [MCAD]: "Re: Reference Types and Value Types"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|