VB.Net program to demonstrate the default property

Here, we are going to demonstrate the default property in VB.Net.
Submitted by Nidhi, on January 02, 2021

Here, we will create a class and implement default property to set and get values of data members using the object of the class.

Program/Source Code:

The source code to demonstrate the default property is given below. The given program is compiled and executed successfully.

' program to demonstrate default property.

Class Sample
    Dim countries(5) As String
    Default Public Property country(ByVal index As Integer) As String
            Return countries(index)
        End Get
        Set(ByVal value As String)
            countries(index) = value
        End Set
    End Property

End Class
Module Module1
    Sub Main()
        Dim S As New Sample()

        S(0) = "India"
        S(1) = "Australia"
        S(2) = "America"
        S(3) = "Canada"

        Console.WriteLine("Country Names:")
        For i = 0 To 3 Step 1
            Console.WriteLine(vbTab & S(i))
    End Sub
End Module


Country Names:
Press any key to continue . . .


In the above program, we created a class Sample that contains a data member countries. Here, countries is an array of strings. Here, we implemented a default property to set and get the values of the countries array.

After that, we created a module Module1 that contains the Main() method, the Main() method is the entry point for the program. And, we created an object of the Sample class and then set the values of data members using object name with specified index and then print the country names on the console screen.

VB.Net Basic Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.