[VB.NET]ByValキーワードで値渡しのサンプル

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

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(ByVal 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(ByVal 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(ByVal y)
            y = y * 2
            Console.WriteLine(y)
      End Sub
End Module

実行結果
5
10

VB.net

Posted by arkgame