Skip to content

[Q] A .foreach magic method "secret" #12607

@scriptingstudio

Description

@scriptingstudio

I have found at least one difference how this method works with different types.

$array = 1,2,3,4,5,6
$arraylist = [System.Collections.ArrayList]::new(@(1,2,3,4,5,6))
$list = [System.Collections.Generic.List[object]]::new(@(1,2,3,4,5,6))

$array.foreach{$_}
1
2
3
4
5
6

$arraylist.foreach{$_}
1
2
3
4
5
6

$list.foreach{$_}
# nothing

# workaround
@($list).foreach{$_}
1
2
3
4
5
6

Is it a type limitation, feature, or bug?
Foreach-Object cmdlet works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions