Create Class in Visual Basic .NET

August 28, 2017

You can use this code to create class called People. It has three properties First Name, Last Name and Date of Birth

Public Class People
    Private strFirstName As String
    Private strLastName As String
    Private dtrDateOfBirth As Date
    Public Property FirstName() As String
        Get
            Return strFirstName
        End Get
        Set(value As String)
            strFirstName = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return strLastName
        End Get
        Set(value As String)
            strLastName = value
        End Set
    End Property


    Public Property DateOfBirth() As String
        Get
            Return dtrDateOfBirth
        End Get
        Set(value As String)
            dtrDateOfBirth = value
        End Set
    End Property



End Class

Now you can create object using following code

Module Module1

    Sub Main()

        Dim p As New People
        p.FirstName = "John"
        p.LastName = "Doe"
        p.DateOfBirth = Date.Parse("11-09-1980")
    End Sub

End Module

Here I am just creating the object from the class and assign values for the properties