Powershell Options Declaration Alternatives

What is the difference between:

function foo ([int] i, [string] s) { ... } 

and

 function foo { param ( [int] i, [string] s ) { ... } } 

MSDN Help does not explain this. Thank you

+4
source share
3 answers

Except for convenience, there is no difference. Both methods are valid. Using a parameter (in my opinion) is more readable, especially in advanced functions, where a parameter declaration can contain several lines of code, and you can use indentation and line breaks.

+3
source

No difference in this case. You may need to use a param declaration for advanced function parameters.

+1
source

Param operators are needed in scripts and scripts where there is no natural place to define parameters, for example, in a function. Manojlds is correct that you have many possibilities to use the advanced "options" functions to overload your function parameters if you use the param operator, which you cannot use in a more traditional parameter list.

+1
source

Source: https://habr.com/ru/post/1411381/


All Articles