ref parameters in a params array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MidiMick
    New Member
    • Jun 2007
    • 1

    #1

    ref parameters in a params array

    It does not seeem to be possible to pass ref params in a param array eg:


    Code:
    public void TestFunc(params object[] Params) {
        ...
    }
    ...
    TestFunc(ref Param);
    ...
    Any ideas?

    Thanks.
  • chinu
    New Member
    • Jun 2007
    • 36

    #2
    Originally posted by MidiMick
    It does not seeem to be possible to pass ref params in a param array eg:


    Code:
    public void TestFunc(params object[] Params) {
        ...
    }
    ...
    TestFunc(ref Param);
    ...
    Any ideas?

    Thanks.
    You cannot use ref or out keys with "params". Btw what is your intention while doing this?

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #3
      I can only think of a few examples where using params is a good idea (string.format, for one). Perhaps you should rethink what you are trying to do.

      And on that note, what exactly is the scope of this issue?

      As far as the params is concerned, I believe that you cannot create a ref because there is not an actual object ever passed to the method. You are creating a new array and passing that.

      My suggestion to get this idea to work is a small workaround like:

      [CODE=cpp]public object[] TestFunc(params object[] Params) {
      object[] result = Params;
      ...
      return result;
      }
      ...
      ParamArray = TestFunc(Param) ;
      // OR
      // Param = TestFunc(Param)[0]
      ...[/CODE]

      Comment

      Working...