You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in Get-Foo cmdlet" instead of "Typo."
Verify Version: If there is a mismatch between documentation and the behavior on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.
Arrays of zero or one
Beginning in Windows PowerShell 3.0, a collection of zero or one object has the Count and Length properties.
[...]
I think this section in general could be improved. The section is titled "Arrays of [...]", but the first two examples are for scalars, which is confusing. Perhaps retitle the section and focus it specifically on PS's implicit enumeration and other pipeline semantics that may yield either a scalar or collection result.
An array, regardless of element count, has a Count and Length that reflects the number of elements.
Count is only added as an ETS AliasProperty to arrays in Windows PowerShell v5.1 or lower. This was due to PS v2's inability to expose explicit interface implementations.
This limitation was addressed in PS v3 and as of PS v6, the AliasProperty is no longer added to the [array] type (it was obsolete and removal of it addressed issues such as PowerShell/PowerShell#3153).
In PS v6+, arrays have a Count property from explicit ICollection implementation.
The text was updated successfully, but these errors were encountered:
surfingoldelephant
changed the title
Incorrect information on the type-native Count/Length properties of an array
Incorrect information on Count/Length properties of an array
Jan 2, 2025
Prerequisites
Get-Foo
cmdlet" instead of "Typo."Links
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays#count-or-length-or-longlength
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays#arrays-of-zero-or-one
Summary
In about_arrays, information on
Count
/Length
is either incorrect or misleading. The documentation states:Count
is not an alias ofLength
in PS v6+. See the details below.Count
should not be referred to as an alias. For consistency across different collection types,Count
should be recommended as the preferred method to retrieve the number of elements of a collection. See Recommend usingCount
to retrieve the number of elements in an in-memory collection #11614.Count
andLength
that reflects the number of elements.Count
or aLength
or neither. See Incorrect assertion that intrinsicCount
/Length
properties are available to all collection types #11613.Details
Count
is only added as an ETSAliasProperty
to arrays in Windows PowerShell v5.1 or lower. This was due to PS v2's inability to expose explicit interface implementations.This limitation was addressed in PS v3 and as of PS v6, the
AliasProperty
is no longer added to the[array]
type (it was obsolete and removal of it addressed issues such as PowerShell/PowerShell#3153).In PS v6+, arrays have a
Count
property from explicitICollection
implementation.The text was updated successfully, but these errors were encountered: