Default method parameter?

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

    Default method parameter?

    Hi

    What is c# default parameter passing for a method ? Is it ref?

    Is this valid to change the object info in a method?

    Class1
    {
    public string name;
    int temp;
    }
    class test:
    {
    Main ()
    {
    class1 cs = new class1();

    Update (cs);

    //I should have here the following
    //cs.name = "new name";
    //cs.temp = 5;
    }

    void Update (Class1 cs)
    {
    cs.name = "new name";
    cs.temp = 5;
    }
    }


    Thanks,
    Ronen


  • Mattias Sjögren

    #2
    Re: Default method parameter?

    Ronen,
    [color=blue]
    >What is c# default parameter passing for a method ? Is it ref?[/color]

    If you don't specify ref or out, it's passed by value.

    [color=blue]
    >Is this valid to change the object info in a method?[/color]

    Yes



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org

    Please reply only to the newsgroup.

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Default method parameter?

      RA <ron_a1@hotmail .com> wrote:[color=blue]
      > What is c# default parameter passing for a method ? Is it ref?[/color]

      See http://www.pobox.com/~skeet/csharp/parameters.html

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...