Posted by: Sourav | August 4, 2016

Optional parameters in Visual Basic


Module Module1

    Sub Main()
        Dim student1 As student = New student()
        student1.printname()
        Console.ReadLine()

    End Sub

    
End Module

 

Class student
    Dim firstname As String
    Dim secondname As String
   

    Sub New(Optional ByVal firstname As String = “no first name provided”, Optional ByVal secondname As String = “no lastname provided”)
        If firstname = “no first name provided” And secondname = “no lastname provided” Then
            Me.firstname = “no first name provided”
            Me.secondname = “no lastname provided”
        Else
            Me.firstname = firstname
            Me.secondname = secondname

        End If
        

    End Sub

    Sub printname()
        ‘  Console.WriteLine(“The student’s name is {0} {1}”, Me.firstname, Me.secondname)
        Console.WriteLine(“The student’s name is {0} {1}”, Me.firstname, Me.secondname)
    End Sub

    Protected Overrides Sub Finalize()

    End Sub
End Class

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: