「Windows/powershell/クラス」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
(→サンプル) |
||
| 行5: | 行5: | ||
[string] hello() { | [string] hello() { | ||
return "Hello!!" | return "Hello!!" | ||
| + | } | ||
| + | [void] test() { | ||
| + | Write-Host "hoge" | ||
} | } | ||
} | } | ||
$helloObj = New-Object HelloClass | $helloObj = New-Object HelloClass | ||
$helloObj.hello() | $helloObj.hello() | ||
| + | $helloObj.test() # hoge | ||
</pre> | </pre> | ||
参考:https://www.vwnet.jp/Windows/PowerShell/2017082401/PSv5Class06.htm | 参考:https://www.vwnet.jp/Windows/PowerShell/2017082401/PSv5Class06.htm | ||
2021年8月23日 (月) 16:25時点における版
サンプル
HelloClass.ps1
class HelloClass {
[string] hello() {
return "Hello!!"
}
[void] test() {
Write-Host "hoge"
}
}
$helloObj = New-Object HelloClass
$helloObj.hello()
$helloObj.test() # hoge
参考:https://www.vwnet.jp/Windows/PowerShell/2017082401/PSv5Class06.htm
サンプル静的クラス
HelloUtil.ps1
class HelloUtil {
static [int] hello([int] $test) {
return $test
}
}
[HelloUtil]::hello(11)
