The following PowerShell code:
class MyClass { }
class MyClass1 : MyClass {
[void] OutMsg([string] $Str) {
Write-Host -Object "MyClass1: $Str"
}
}
class MyClass2 : MyClass {
[void] OutMsg([string] $Str) {
Write-Host -Object "MyClass2: $Str"
}
}
[MyClass[]] $ClassArray = @([MyClass1]::new(), [MyClass2]::new())
$ClassArray.OutMsg('TestString')
outputs:
MyClass1: TestString
MyClass2: TestString
Calling
Get-Member -InputObject $ClassArray
shows me that the array object itself has no OutMsg method.
Why can I call $ClassArray.OutMsg('') though (looks like this calls the OutMsg method of each array member in turn)?