Posted by: Sourav | August 17, 2016

different ways of passing parameters in subroutines ,VB Teacher Sourav


Option Strict On
Option Explicit On
Imports System
‘This is about method parameters in VB
Module Module1

Sub Main()
Dim i As Integer = 25
passvalmethod(i)
Console.WriteLine(“i is when passing by value ” & i)
passrefmethod(i)
Console.WriteLine(“i is when passing by reference ” & i)
Dim numbers(2) As Integer
numbers(0) = 0
numbers(1) = 1
numbers(2) = 2
varparamsmethod(numbers)
varparamsmethod(1, 2)
varparamsmethod()

Console.ReadLine()

 

 

End Sub
Sub passvalmethod(ByVal i As Integer)
i = 100

End Sub
Sub passrefmethod(ByRef i As Integer)
i = 100

End Sub

Sub varparamsmethod(ByVal ParamArray data() As Integer)
Console.WriteLine(“The array’s length is ” & data.Length)
Dim i As Integer
‘ If data.Length <> 0 Then
‘For Each i In data
‘Console.WriteLine(“array element is ” & data(i))

‘Next
‘End If
For i = 0 To UBound(data)
Console.WriteLine(“array element is ” & data(i))
Next
End Sub

End Module

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: