passing object reference to the method



Say I pass an object of a class (reference value I suppose) to a
method, and I want to pass it by reference. Do I need to preappend
it with ref.

public interface IFoo{}

public class Foo:IFoo{

}

void FromHere()
{

Foo f=new Foo();
Here(ref f);

}

void Here(ref IFoo f )
{
//do something with f
}

Is ref redundant or error-prone. In my scenerio I have a lot of
overload for Here-like function,
and compiler screams that it cannot convert IFoo to char (latter
beeing void Here(ref char c) )


Thanks
.



Relevant Pages

  • Re: back once again...
    ... reference to type ... a, signed char ... int dycObjectP(dyt obj); ... void dycBeginClass; ...
    (comp.lang.misc)
  • Re: pass by reference
    ... char *something; ... You can, if you really need, do something similar to pass by reference, and that is by explicitly passing the address of a variable. ... void AllocateSomething ...
    (comp.lang.c)
  • Re: Passing structs....
    ... void func{ ... int main{ ... char x; ... But a pass by reference in C++ would include the trailing &. ...
    (microsoft.public.vc.language)
  • Re: type-punning?
    ... The problem is that dat is defined as char *. ... defined as a void *. ... pointer by passing a reference to it to a function? ...
    (comp.lang.c)
  • [PATCH 12/15] dm: add exports
    ... Export core device-mapper functions for manipulating mapped devices ... void dm_get ... struct dm_target; ... * Drop the reference with dm_put when you finish with the object. ...
    (Linux-Kernel)

Quantcast