Skip to content

Range operator (..): make it clear that integer endpoints refers to [int32], specifically #10906

@mklement0

Description

@mklement0

Type of issue

Missing information

Feedback

The range operator can be used to represent an array of sequential integers

While true, it would should be noted that the endpoints must be (convertible to) [int32] numbers, specifically, i.e. 32-bit signed integers. Larger integer values cause an error.

For instance, the following fail:

1..([uint32]::MaxValue)

1gb..1tb  # 1tb is [int64]

Additionally, the count of resulting numbers is limited to:

  • [int]::MaxValue - 56 (2147483591) when the result is captured in an array, as implicitly happens as part of an expression; this is due to the fact that said number is the max. count of elements in a .NET array

  • in streaming processing, where the numbers are created and consumed on demand, one by one, the only thing that matters is whether the endpoints fit into [int], which makes the effective limit on the element count [uint]::MaxValue + 1 (4294967296)

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators?view=powershell-7.4#range-operator-

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.4/Microsoft.PowerShell.Core/About/about_Operators.md

Author

@sdwheeler

Document Id

1ef1d966-3ba7-77aa-abb2-fb255d08da46

Metadata

Metadata

Assignees

Labels

area-aboutArea - About_ topics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions