[VB.NET]ByRefキーワードで参照渡しをするサンプル

2021年4月22日

書式
メソッド名(ByRef 変数名)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module ModuleTest
Sub Main()
Dim y as Integer = 5
testFunc(y)
Console.WriteLine(y)
End Sub
Sub testFunc(ByRef y)
y = y * 2
Console.WriteLine(y)
End Sub
End Module
Module ModuleTest Sub Main() Dim y as Integer = 5 testFunc(y) Console.WriteLine(y) End Sub Sub testFunc(ByRef y) y = y * 2 Console.WriteLine(y) End Sub End Module
Module ModuleTest
      Sub Main()
            Dim y as Integer = 5
            testFunc(y)
            Console.WriteLine(y) 
      End Sub
      Sub testFunc(ByRef y)
            y = y * 2
            Console.WriteLine(y)
      End Sub
End Module

実行結果
10
10

Software

Posted by arkgame