Re: Object Parameters, they are passed as pointers, yes?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Stoitcho Goutsev \(100\) [C# MVP] (100_at_100.com)
Date: 02/05/04


Date: Thu, 5 Feb 2004 09:40:54 -0500

Hi Derrick,
> I saw the ref param keyword relating to base types. Just checking, if I
> pass an object around to other class constructors, there will only be one
> instance of the object, correct?

Yes, if the object is an instance of reference type (class). If the
paramter is of valuetype (struct, enum) you will have a copy of that object
for each of the classes.

But if you have parameter of type *object*
void Foo(object param)
{
}

That param might be reference to an instance of a class or boxed valuetype.
Eventhough you might share the reference to a boxed value type in the
managed heap you cannot use it for sharing data because to use the type
(read/write its properties and fields call some of its methods) you have to
unbox that valuetype and then you will have a private copy. Thus, the
changes won't go in the original.

B\rgds
100



Relevant Pages

  • Re: ref params
    ... The REFERENCE was passed by value. ... my DataTable param var is populated. ... that it was passed by ref, ... in C#, in order to declare a parameter as ref, you need to declare it as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pass by reference or by value?
    ... param = 5 sets the local variable "param" to whatever 5 is. ... The local variable "param" doesn't *have* a type, and can be a reference to a value of any type. ... That hack makes sure that a method of the passed object is called instead of of the local namespace dict. ... (please note that I'm throwing around abstract concepts without caring about an implementation). ...
    (comp.lang.python)
  • Re: overriding method with different return type
    ... Paul J. Lucas wrote: ... > Derived's param() to return a reference to Derived.ParamBlock. ... That will be legal in 1.5 (you can try out the beta to confirm). ...
    (comp.lang.java.programmer)
  • Re: Convert Delphi to C#
    ... > string test(string param) ... > C# Programmer's Reference: ... > Best regards, ... > Carlos J. Quintero ...
    (microsoft.public.dotnet.languages.csharp)