LoginSignup
2
3

More than 1 year has passed since last update.

Powershellのコンストラクタ

Posted at

Powershellのコンストラクタの実装例です。

class Hinatazaka{
    [int] $id
    [String] $name 
    #コンストラクタ
    Hinatazaka([int] $id,[String] $name) {
        $this.id = $id 
        $this.name = $name    
    }
    #メソッド
    [void] Disp() {
         Write-Host( $this.name + "のid番号は" + $this.id + "です")  
    }
}

#インスタンス化
$rei1 = New-Object Hinatazaka(1,"佐々木久美")
#呼び出し
$rei1.Disp()

#インスタンス化
$rei2 = New-Object Hinatazaka(2,"加藤史帆")
#呼び出し
$rei2.Disp()

$rei3 = New-Object Hinatazaka(3,"影山優佳")
$rei3.Disp()


2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3