diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md index cd001e7421f1..7ae440184d46 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md @@ -1,7 +1,7 @@ --- description: Describes automatic members in all PowerShell objects Locale: en-US -ms.date: 07/14/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_Inrinsic_Members?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Intrinsic_Members @@ -95,4 +95,38 @@ information on how to use these methods, see [about_Arrays](about_Arrays.md). The **Count** and **Length** properties are available to all PowerShell objects. These are similar to each other but may work differently depending on -the data type. For more information about these properties, see [about_Properties](about_Properties.md). +the data type. For more information about these properties, see +[about_Properties](about_Properties.md). + +## Array indexing scalar types + +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + +For more information, see [about_Operators](about_Operators.md#index-operator--). + +## New() method for types + +Beginning in PowerShell 5.0, PowerShell adds a static `New()` method for all +.NET types. The following examples produce the same result. + +```powershell +$expression = New-Object -TypeName regex -ArgumentList 'pattern' +$expression = [regex]::new('pattern') +``` + +Using the `new()` method performs better than using `New-Object`. + +For more information, see [about_Classes](about_Classes.md). diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md index 20a2e9753b76..1ac3005434c8 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -1,7 +1,7 @@ --- description: Describes the operators that are supported by PowerShell. Locale: en-US -ms.date: 06/08/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Operators @@ -346,16 +346,12 @@ method and [Composite Formatting](/dotnet/standard/base-types/composite-formatti ### Index operator `[ ]` Selects objects from indexed collections, such as arrays and hash tables. Array -indexes are zero-based, so the first object is indexed as `[0]`. For arrays -(only), you can also use negative indexes to get the last values. Hash tables -are indexed by key value. +indexes are zero-based, so the first object is indexed as `[0]`. You can also +use negative indexes to get the last values. Hash tables are indexed by key +value. -Given a list of indices, -the index operator returns a list of members corresponding to those indices. - -If an object is not an indexed collection, -accessing its first element returns the object itself. -Index values beyond the first element return `$null`. +Given a list of indices, the index operator returns a list of members +corresponding to those indices. ``` PS> $a = 1, 2, 3 @@ -367,14 +363,6 @@ PS> $a[2, 1, 0] 3 2 1 -PS> (2)[0] -2 -PS> (2)[-1] -2 -PS> (2)[1] -eq $null -True -PS> (2)[0,0] -eq $null -True ``` ```powershell @@ -401,6 +389,21 @@ intro Once upon a time... ``` +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + ### Pipeline operator `|` Sends ("pipes") the output of the command that precedes it to the command that diff --git a/reference/7.0/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md b/reference/7.0/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md index 1068d4c96929..793e070ac9da 100644 --- a/reference/7.0/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md +++ b/reference/7.0/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md @@ -1,7 +1,7 @@ --- description: Describes automatic members in all PowerShell objects Locale: en-US -ms.date: 06/01/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_Inrinsic_Members?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Intrinsic_Members @@ -95,4 +95,38 @@ information on how to use these methods, see [about_Arrays](about_Arrays.md). The **Count** and **Length** properties are available to all PowerShell objects. These are similar to each other but may work differently depending on -the data type. For more information about these properties, see [about_Properties](about_Properties.md). +the data type. For more information about these properties, see +[about_Properties](about_Properties.md). + +## Array indexing scalar types + +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + +For more information, see [about_Operators](about_Operators.md#index-operator--). + +## New() method for types + +Beginning in PowerShell 5.0, PowerShell adds a static `New()` method for all +.NET types. The following examples produce the same result. + +```powershell +$expression = New-Object -TypeName regex -ArgumentList 'pattern' +$expression = [regex]::new('pattern') +``` + +Using the `new()` method performs better than using `New-Object`. + +For more information, see [about_Classes](about_Classes.md). diff --git a/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md b/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md index ed748e272237..f9f71a771fbb 100644 --- a/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md @@ -1,7 +1,7 @@ --- description: Describes the operators that are supported by PowerShell. Locale: en-US -ms.date: 06/08/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Operators @@ -413,16 +413,12 @@ method and [Composite Formatting](/dotnet/standard/base-types/composite-formatti ### Index operator `[ ]` Selects objects from indexed collections, such as arrays and hash tables. Array -indexes are zero-based, so the first object is indexed as `[0]`. For arrays -(only), you can also use negative indexes to get the last values. Hash tables -are indexed by key value. +indexes are zero-based, so the first object is indexed as `[0]`. You can also +use negative indexes to get the last values. Hash tables are indexed by key +value. -Given a list of indices, -the index operator returns a list of members corresponding to those indices. - -If an object is not an indexed collection, -accessing its first element returns the object itself. -Index values beyond the first element return `$null`. +Given a list of indices, the index operator returns a list of members +corresponding to those indices. ``` PS> $a = 1, 2, 3 @@ -434,14 +430,6 @@ PS> $a[2, 1, 0] 3 2 1 -PS> (2)[0] -2 -PS> (2)[-1] -2 -PS> (2)[1] -eq $null -True -PS> (2)[0,0] -eq $null -True ``` ```powershell @@ -468,6 +456,21 @@ intro Once upon a time... ``` +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + ### Pipeline operator `|` Sends ("pipes") the output of the command that precedes it to the command that diff --git a/reference/7.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md b/reference/7.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md index f0744154eff7..97c1474c14d9 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md @@ -1,7 +1,7 @@ --- description: Describes automatic members in all PowerShell objects Locale: en-US -ms.date: 07/14/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_Inrinsic_Members?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Intrinsic_Members @@ -95,4 +95,38 @@ information on how to use these methods, see [about_Arrays](about_Arrays.md). The **Count** and **Length** properties are available to all PowerShell objects. These are similar to each other but may work differently depending on -the data type. For more information about these properties, see [about_Properties](about_Properties.md). +the data type. For more information about these properties, see +[about_Properties](about_Properties.md). + +## Array indexing scalar types + +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + +For more information, see [about_Operators](about_Operators.md#index-operator--). + +## New() method for types + +Beginning in PowerShell 5.0, PowerShell adds a static `New()` method for all +.NET types. The following examples produce the same result. + +```powershell +$expression = New-Object -TypeName regex -ArgumentList 'pattern' +$expression = [regex]::new('pattern') +``` + +Using the `new()` method performs better than using `New-Object`. + +For more information, see [about_Classes](about_Classes.md). diff --git a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md index 426758851d52..a31a0d5ad352 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -1,7 +1,7 @@ --- description: Describes the operators that are supported by PowerShell. Locale: en-US -ms.date: 06/08/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Operators @@ -413,16 +413,12 @@ method and [Composite Formatting](/dotnet/standard/base-types/composite-formatti ### Index operator `[ ]` Selects objects from indexed collections, such as arrays and hash tables. Array -indexes are zero-based, so the first object is indexed as `[0]`. For arrays -(only), you can also use negative indexes to get the last values. Hash tables -are indexed by key value. +indexes are zero-based, so the first object is indexed as `[0]`. You can also +use negative indexes to get the last values. Hash tables are indexed by key +value. -Given a list of indices, -the index operator returns a list of members corresponding to those indices. - -If an object is not an indexed collection, -accessing its first element returns the object itself. -Index values beyond the first element return `$null`. +Given a list of indices, the index operator returns a list of members +corresponding to those indices. ``` PS> $a = 1, 2, 3 @@ -434,14 +430,6 @@ PS> $a[2, 1, 0] 3 2 1 -PS> (2)[0] -2 -PS> (2)[-1] -2 -PS> (2)[1] -eq $null -True -PS> (2)[0,0] -eq $null -True ``` ```powershell @@ -468,6 +456,21 @@ intro Once upon a time... ``` +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + ### Pipeline operator `|` Sends ("pipes") the output of the command that precedes it to the command that diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md index f64b64687a0e..30858cc3bd10 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Intrinsic_Members.md @@ -1,7 +1,7 @@ --- description: Describes automatic members in all PowerShell objects Locale: en-US -ms.date: 07/14/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_Inrinsic_Members?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about_Intrinsic_Members @@ -95,4 +95,38 @@ information on how to use these methods, see [about_Arrays](about_Arrays.md). The **Count** and **Length** properties are available to all PowerShell objects. These are similar to each other but may work differently depending on -the data type. For more information about these properties, see [about_Properties](about_Properties.md). +the data type. For more information about these properties, see +[about_Properties](about_Properties.md). + +## Array indexing scalar types + +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + +For more information, see [about_Operators](about_Operators.md#index-operator--). + +## New() method for types + +Beginning in PowerShell 5.0, PowerShell adds a static `New()` method for all +.NET types. The following examples produce the same result. + +```powershell +$expression = New-Object -TypeName regex -ArgumentList 'pattern' +$expression = [regex]::new('pattern') +``` + +Using the `new()` method performs better than using `New-Object`. + +For more information, see [about_Classes](about_Classes.md). diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md index 34fec7812373..b555e678613b 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md @@ -1,7 +1,7 @@ --- description: Describes the operators that are supported by PowerShell. Locale: en-US -ms.date: 06/08/2021 +ms.date: 11/16/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Operators @@ -413,16 +413,12 @@ method and [Composite Formatting](/dotnet/standard/base-types/composite-formatti ### Index operator `[ ]` Selects objects from indexed collections, such as arrays and hash tables. Array -indexes are zero-based, so the first object is indexed as `[0]`. For arrays -(only), you can also use negative indexes to get the last values. Hash tables -are indexed by key value. +indexes are zero-based, so the first object is indexed as `[0]`. You can also +use negative indexes to get the last values. Hash tables are indexed by key +value. -Given a list of indices, -the index operator returns a list of members corresponding to those indices. - -If an object is not an indexed collection, -accessing its first element returns the object itself. -Index values beyond the first element return `$null`. +Given a list of indices, the index operator returns a list of members +corresponding to those indices. ``` PS> $a = 1, 2, 3 @@ -434,14 +430,6 @@ PS> $a[2, 1, 0] 3 2 1 -PS> (2)[0] -2 -PS> (2)[-1] -2 -PS> (2)[1] -eq $null -True -PS> (2)[0,0] -eq $null -True ``` ```powershell @@ -468,6 +456,21 @@ intro Once upon a time... ``` +When an object is not an indexed collection, using the index operator to access +the first element returns the object itself. Index values beyond the first +element return `$null`. + +``` +PS> (2)[0] +2 +PS> (2)[-1] +2 +PS> (2)[1] -eq $null +True +PS> (2)[0,0] -eq $null +True +``` + ### Pipeline operator `|` Sends ("pipes") the output of the command that precedes it to the command that