Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #10906 - Document range limits #10907

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 01/19/2024
ms.date: 02/26/2024
online version: https://learn.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
Expand Down Expand Up @@ -521,8 +521,13 @@ You can also create ranges in reverse order.
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer. For example, you could use the members of an
enumeration for your start and end values.
evaluate to an integer or a character. The endpoints of the range must be
convertible to signed 32-bit integers (`[int32]`). Larger values cause an
error. Also, if the range is captured in an array, the count of resulting is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround, but the word "numbers" is presumably missing after "count of resulting", and "the" is missing before "maximum size".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh!

limited to maximum size of an array in .NET, which is `[int]::MaxValue - 56`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention that this limit only applies to PowerShell (Core) / .NET (Core). In Windows PowerShell / .NET Framework, it is 256MB - 8 (268435448): E.g., (1..268435448).Count works (if you have the patience), whereas (1..268435449).Count fails.


For example, you could use the members of an enumeration for your start and end
values.

```powershell
PS> enum Food {
Expand Down
69 changes: 39 additions & 30 deletions reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 01/19/2024
ms.date: 02/26/2024
online version: https://learn.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
Expand Down Expand Up @@ -575,6 +575,8 @@ values of the range.
> [!NOTE]
> Support for character ranges was added in PowerShell 6.

#### Number ranges

```powershell
1..10
$max = 10
Expand All @@ -588,6 +590,42 @@ You can also create ranges in reverse order.
5..-5 | ForEach-Object {Write-Output $_}
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer or a character. The endpoints of the range must be
convertible to signed 32-bit integers (`[int32]`). Larger values cause an
error. Also, if the range is captured in an array, the count of resulting is
limited to maximum size of an array in .NET, which is `[int]::MaxValue - 56`.

For example, you could use the members of an enumeration for your start and end
values.

```powershell
PS> enum Food {
Apple
Banana = 3
Kiwi = 10
}
PS> [Food]::Apple..[Food]::Kiwi
0
1
2
3
4
5
6
7
8
9
10
```

> [!IMPORTANT]
> The resulting range isn't limited to the values of the enumeration. Instead
> it represents the range of values between the two values provided. You can't
> use the range operator to reliably represent the members of an enumeration.

#### Character ranges

To create a range of characters, enclose the characters in quotes.

```powershell
Expand Down Expand Up @@ -646,35 +684,6 @@ Y
X
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer or a character. For example, you could use the members
of an enumeration for your start and end values.

```powershell
PS> enum Food {
Apple
Banana = 3
Kiwi = 10
}
PS> [Food]::Apple..[Food]::Kiwi
0
1
2
3
4
5
6
7
8
9
10
```

> [!IMPORTANT]
> The resulting range isn't limited to the values of the enumeration. Instead
> it represents the range of values between the two values provided. You can't
> use the range operator to reliably represent the members of an enumeration.

### Member-access operator `.`

Accesses the properties and methods of an object. The member name may be an
Expand Down
69 changes: 39 additions & 30 deletions reference/7.3/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 01/19/2024
ms.date: 02/26/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.3&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -575,6 +575,8 @@ values of the range.
> [!NOTE]
> Support for character ranges was added in PowerShell 6.

#### Number ranges

```powershell
1..10
$max = 10
Expand All @@ -588,6 +590,42 @@ You can also create ranges in reverse order.
5..-5 | ForEach-Object {Write-Output $_}
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer or a character. The endpoints of the range must be
convertible to signed 32-bit integers (`[int32]`). Larger values cause an
error. Also, if the range is captured in an array, the count of resulting is
limited to maximum size of an array in .NET, which is `[int]::MaxValue - 56`.

For example, you could use the members of an enumeration for your start and end
values.

```powershell
PS> enum Food {
Apple
Banana = 3
Kiwi = 10
}
PS> [Food]::Apple..[Food]::Kiwi
0
1
2
3
4
5
6
7
8
9
10
```

> [!IMPORTANT]
> The resulting range isn't limited to the values of the enumeration. Instead
> it represents the range of values between the two values provided. You can't
> use the range operator to reliably represent the members of an enumeration.

#### Character ranges

To create a range of characters, enclose the characters in quotes.

```powershell
Expand Down Expand Up @@ -646,35 +684,6 @@ Y
X
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer or a character. For example, you could use the members
of an enumeration for your start and end values.

```powershell
PS> enum Food {
Apple
Banana = 3
Kiwi = 10
}
PS> [Food]::Apple..[Food]::Kiwi
0
1
2
3
4
5
6
7
8
9
10
```

> [!IMPORTANT]
> The resulting range isn't limited to the values of the enumeration. Instead
> it represents the range of values between the two values provided. You can't
> use the range operator to reliably represent the members of an enumeration.

### Member-access operator `.`

Accesses the properties and methods of an object. The member name may be an
Expand Down
69 changes: 39 additions & 30 deletions reference/7.4/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 01/19/2024
ms.date: 02/26/2024
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -575,6 +575,8 @@ values of the range.
> [!NOTE]
> Support for character ranges was added in PowerShell 6.

#### Number ranges

```powershell
1..10
$max = 10
Expand All @@ -588,6 +590,42 @@ You can also create ranges in reverse order.
5..-5 | ForEach-Object {Write-Output $_}
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer or a character. The endpoints of the range must be
convertible to signed 32-bit integers (`[int32]`). Larger values cause an
error. Also, if the range is captured in an array, the count of resulting is
limited to maximum size of an array in .NET, which is `[int]::MaxValue - 56`.

For example, you could use the members of an enumeration for your start and end
values.

```powershell
PS> enum Food {
Apple
Banana = 3
Kiwi = 10
}
PS> [Food]::Apple..[Food]::Kiwi
0
1
2
3
4
5
6
7
8
9
10
```

> [!IMPORTANT]
> The resulting range isn't limited to the values of the enumeration. Instead
> it represents the range of values between the two values provided. You can't
> use the range operator to reliably represent the members of an enumeration.

#### Character ranges

To create a range of characters, enclose the characters in quotes.

```powershell
Expand Down Expand Up @@ -646,35 +684,6 @@ Y
X
```

The start and end values of the range can be any pair of expressions that
evaluate to an integer or a character. For example, you could use the members
of an enumeration for your start and end values.

```powershell
PS> enum Food {
Apple
Banana = 3
Kiwi = 10
}
PS> [Food]::Apple..[Food]::Kiwi
0
1
2
3
4
5
6
7
8
9
10
```

> [!IMPORTANT]
> The resulting range isn't limited to the values of the enumeration. Instead
> it represents the range of values between the two values provided. You can't
> use the range operator to reliably represent the members of an enumeration.

### Member-access operator `.`

Accesses the properties and methods of an object. The member name may be an
Expand Down
Loading