passing object reference to the method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    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
  • Jon Skeet [C# MVP]

    #2
    Re: passing object reference to the method

    puzzlecracker <ironsel2000@gm ail.comwrote:
    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.
    See http://pobox.com/~skeet/csharp/parameters.html

    --
    Jon Skeet - <skeet@pobox.co m>
    Web site: http://www.pobox.com/~skeet
    Blog: http://www.msmvps.com/jon.skeet
    C# in Depth: http://csharpindepth.com

    Comment

    Working...