4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Powershellでの関数のreturnとクラスでのreturnの違い

Last updated at Posted at 2017-03-13

関数のreturn

  • 現在のスコープを抜ける
  • returnはあってもなくてもいい
  • return以外の他のオブジェクトも返す
function Test-Return
{
	'Hello'
	return 12
	'Good'
}

Test-Return
# Hello
# 12

クラスのreturn

  • 現在のスコープを抜ける
  • returnは必須(ない場合errorになる)
  • returnで指定されたものだけ返す
class ReturnTester
{
    [int32]TestReturn()
    {
        'Hello'
        return 12
        'Good'
    }
}

$return = New-Object -TypeName ReturnTester
$return.TestReturn()
# 12
4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?