From b71e9b2552b15030c525f72590c0e0aca0fe207b Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Sat, 30 Oct 2021 21:37:36 +0200 Subject: [PATCH 1/8] More cast examples, add results --- .../About/about_Operators.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 0699eb1d7923..465e9ca952f6 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -337,10 +337,18 @@ Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error. ```powershell -[DateTime]"2/20/88" - [DateTime]"1/20/88" -[Int] (7/2) -[String] 1 + 0 -[Int] '1' + 0 +# Dates +[DateTime] '2/20/88' - [DateTime] '1/20/88' -EQ [TimeSpan] '31' +# Bankers’ rounding +[Int] (7/2) -EQ 4 -AND [Int] (9/2) -EQ 4 +# Concatenation +[String] 1 + 0 -EQ '10' +# Addition +[Int] '1' + 0 -EQ 1 +# Hexadecimal +[Int] '0XF' -EQ 0XF -AND [Int] '#F' -EQ 0XF -AND [Int] '&HF' -EQ 0XF +# Binary +[Int] '0B1111' -EQ 0B1111 ``` A cast can also be performed when a variable is assigned to using From 62df05c7eea79e84ce20669c7a9198702fa22756 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Fri, 12 Nov 2021 13:05:20 +0100 Subject: [PATCH 2/8] About operator[]: non-arrays, lists of indices Also, remove spurious conversion examples and improve style as requested. --- .../About/about_Operators.md | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) 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 465e9ca952f6..a9c6bd5f2380 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -339,16 +339,10 @@ converted, PowerShell generates an error. ```powershell # Dates [DateTime] '2/20/88' - [DateTime] '1/20/88' -EQ [TimeSpan] '31' -# Bankers’ rounding -[Int] (7/2) -EQ 4 -AND [Int] (9/2) -EQ 4 -# Concatenation -[String] 1 + 0 -EQ '10' -# Addition -[Int] '1' + 0 -EQ 1 # Hexadecimal -[Int] '0XF' -EQ 0XF -AND [Int] '#F' -EQ 0XF -AND [Int] '&HF' -EQ 0XF +[Int] '0xF' -eq 0xF -AND [Int] '#F' -eq 0xF -AND [Int] '&hF' -EQ 0xF # Binary -[Int] '0B1111' -EQ 0B1111 +[Int] '0b1111' -EQ 0b1111 ``` A cast can also be performed when a variable is assigned to using @@ -428,12 +422,31 @@ 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. +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.` + ``` PS> $a = 1, 2, 3 PS> $a[0] 1 PS> $a[-1] 3 +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 From 2a142a6e8a765513af83efb0bd44ac0d1a269d58 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Fri, 12 Nov 2021 18:20:02 +0100 Subject: [PATCH 3/8] move hexadecimal string conversions to literals --- .../7.1/Microsoft.PowerShell.Core/About/about_Operators.md | 5 ----- 1 file changed, 5 deletions(-) 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 a9c6bd5f2380..e11465ec7508 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -337,12 +337,7 @@ Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error. ```powershell -# Dates [DateTime] '2/20/88' - [DateTime] '1/20/88' -EQ [TimeSpan] '31' -# Hexadecimal -[Int] '0xF' -eq 0xF -AND [Int] '#F' -eq 0xF -AND [Int] '&hF' -EQ 0xF -# Binary -[Int] '0b1111' -EQ 0b1111 ``` A cast can also be performed when a variable is assigned to using From c811392670d498dd6720d8af56f29194e783a057 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Nov 2021 23:11:14 +0100 Subject: [PATCH 4/8] -eq lc --- .../7.1/Microsoft.PowerShell.Core/About/about_Operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e11465ec7508..3e3ad431042d 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -337,7 +337,7 @@ Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error. ```powershell -[DateTime] '2/20/88' - [DateTime] '1/20/88' -EQ [TimeSpan] '31' +[DateTime] '2/20/88' - [DateTime] '1/20/88' -eq [TimeSpan] '31' ``` A cast can also be performed when a variable is assigned to using From 7e1174e5b9470e7c1c71e12ba44eca57b1085c97 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Nov 2021 23:12:57 +0100 Subject: [PATCH 5/8] fix `$null`. --- .../7.1/Microsoft.PowerShell.Core/About/about_Operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3e3ad431042d..426758851d52 100644 --- a/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -422,7 +422,7 @@ 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.` +Index values beyond the first element return `$null`. ``` PS> $a = 1, 2, 3 From 5ac9c20adc1adc770254a2f9fda5d7cb73b2ad0b Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Nov 2021 23:15:07 +0100 Subject: [PATCH 6/8] Add more examples to about_Operators Port from 7.1 --- .../About/about_Operators.md | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 46e47ed4eec4..34fec7812373 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md @@ -337,10 +337,7 @@ Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error. ```powershell -[DateTime]"2/20/88" - [DateTime]"1/20/88" -[Int] (7/2) -[String] 1 + 0 -[Int] '1' + 0 +[DateTime] '2/20/88' - [DateTime] '1/20/88' -eq [TimeSpan] '31' ``` A cast can also be performed when a variable is assigned to using @@ -420,12 +417,31 @@ 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. +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`. + ``` PS> $a = 1, 2, 3 PS> $a[0] 1 PS> $a[-1] 3 +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 From 958a739824fc9ae7dbfaf2b22697a7c3f6c7ff8c Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Nov 2021 23:18:03 +0100 Subject: [PATCH 7/8] Add more examples to about_Operators Backport from 7.1 --- .../About/about_Operators.md | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 da4bc039a5a2..ed748e272237 100644 --- a/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md @@ -337,10 +337,7 @@ Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error. ```powershell -[DateTime]"2/20/88" - [DateTime]"1/20/88" -[Int] (7/2) -[String] 1 + 0 -[Int] '1' + 0 +[DateTime] '2/20/88' - [DateTime] '1/20/88' -eq [TimeSpan] '31' ``` A cast can also be performed when a variable is assigned to using @@ -420,12 +417,31 @@ 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. +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`. + ``` PS> $a = 1, 2, 3 PS> $a[0] 1 PS> $a[-1] 3 +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 From 11e857cc5dc69d8ab9cba401197534bad148085b Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Mon, 15 Nov 2021 23:21:03 +0100 Subject: [PATCH 8/8] Add more examples to about_Operators Backport from 7.1 --- .../About/about_Operators.md | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 e56200bb195c..20a2e9753b76 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md @@ -270,10 +270,7 @@ Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error. ```powershell -[DateTime]"2/20/88" - [DateTime]"1/20/88" -[Int] (7/2) -[String] 1 + 0 -[Int] '1' + 0 +[DateTime] '2/20/88' - [DateTime] '1/20/88' -eq [TimeSpan] '31' ``` A cast can also be performed when a variable is assigned to using @@ -353,12 +350,31 @@ 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. +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`. + ``` PS> $a = 1, 2, 3 PS> $a[0] 1 PS> $a[-1] 3 +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