Erik Movsesyan

Erik Movsesyan

  • NA
  • 62
  • 5.9k

using ref or out modifiers with params modifier

Jun 8 2022 10:25 PM

Hello, I have the following code here and I know that this will not compile as I am trying to use the ref modifier with the params modifier

 

    public static int[] Findfactors(ref params int[] pro) {

        int[] hjk = { 88, 99 };
        pro = hjk;
        return pro;
    }

I am just trying to make the "pro" point to the "hjk" but I can not do that.
Why does't C# allow us to do that? why can't I use ref or out with params? 

 

My best guess is the following:

The params has a property where it lets you not to pass any argument to a parameter that has the params modifier and so ,

with the example of this case, if I would not pass any argument to "pro" and then try to make pro point to "hjk", I would literally make "Nothing" point to something which would obviously not make any sense.