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

Incorrect information on Count/Length properties of an array #11615

Closed
3 tasks done
surfingoldelephant opened this issue Dec 28, 2024 · 0 comments · Fixed by #11626
Closed
3 tasks done

Incorrect information on Count/Length properties of an array #11615

surfingoldelephant opened this issue Dec 28, 2024 · 0 comments · Fixed by #11626
Assignees
Labels
area-about Area - About_ topics issue-doc-bug Issue - error in documentation

Comments

@surfingoldelephant
Copy link

surfingoldelephant commented Dec 28, 2024

Prerequisites

  • 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.

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:

To determine how many items are in an array, use the Length property or its Count alias.

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.
  • Other collection types may only have a Count or a Length or neither. See Incorrect assertion that intrinsic Count/Length properties are available to all collection types #11613.

Details

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.

@surfingoldelephant surfingoldelephant added issue-doc-bug Issue - error in documentation needs-triage Waiting - Needs triage labels Dec 28, 2024
@sdwheeler sdwheeler added area-about Area - About_ topics and removed needs-triage Waiting - Needs triage labels Dec 30, 2024
@surfingoldelephant 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
@sdwheeler sdwheeler self-assigned this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-about Area - About_ topics issue-doc-bug Issue - error in documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants