Skip to content

class Person {
    [string] $Name
    [int] $Age

    Person([string]$Name, [int]$Age) {
        $this.Name = $Name
        $this.Age = $Age
    }
}

class People {
    [string] $Name
    [int] $Age

    People([hashtable]$Info) {
        switch ($Info.Keys) {
            'Name' { $this.Name = $Info.Name }
            'Age' { $this.Age = $Info.Age }
        }
    }
}

[Person]::new('David', 30)

[People]::new(@{
    Name = 'Bob'
    Age = 25
})
NameAge
David30
Bob25

联系 math@baima.site