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