I am having an issue with initializing an array in my class. In the constructor of the class I set a hierarchy depth to be later used for initializing an array of that size. If I just use [int]$Depth = 8 everything works fine, however if I try to pass the $Depth via the constructor it is not working (Error: Cannot index into a null array). What am I doing wrong?
Part of the code:
class Hierarchy {
[int]$Depth = 8 // If I add a number here it works
[string]$Name
[string]$HideMembers
#Constructor
Hierarchy ([string] $Name, [string] $HideMembers, [int] $Depth)
{
$this.Name = $Name
$this.HideMembers = $HideMembers
$this.Depth = $Depth // it seems this is executed after the creation of the $levels array
}
[Level[]]$Levels = [Level[]]::new($this.Depth)
