Cross-referencing parameters

When executing a param block, it is possible to cross-reference parameters. That is, the default value of a parameter can be based on the value of another parameter. This is shown here:

function Get-Substring {
param (
[String]$String,

[Int]$Start,

[Int]$Length = ($String.Length - $Start)
)

$String.Substring($Start, $Length)
}

The value of the Length parameter will use the default, derived from the first two parameters, unless the user of the function supplies their own value. The order of the parameters is important here: the Start parameter must be created before it can be used in the default value for Length.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.93.30