ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to implement WriteOnly property

Here, we are going to learn how to implement WriteOnly property in VB.Net?
Submitted by Nidhi, on January 02, 2021

Here, we will create a class and implement Set properties using the WriteOnly keyword to set the values to the data members.

Program/Source Code:

The source code to implement the WriteOnly property is given below. The given program is compiled and executed successfully.

'VB.net program to implement WriteOnly property

Class Student
    Dim Id As Integer
    Dim Name As String

    Public WriteOnly Property StudentID As Integer
        Set(value As Integer)
            Id = value
        End Set
    End Property

    Public WriteOnly Property StudentName As String
        Set(value As String)
            Name = value
        End Set
    End Property

    Sub PrintInfo()
        Console.WriteLine("Student Id  : {0}", Id)
        Console.WriteLine("Student Name: {0}", Name)
    End Sub
End Class

Module Module1
    Sub Main()
        Dim Stu As New Student()

        Stu.StudentID = 101
        Stu.StudentName = "Rohit Kohli"

        Stu.PrintInfo()
    End Sub
End Module

Output:

Student Id  : 101
Student Name: Rohit Kohli
Press any key to continue . . .

Explanation:

In the above program, we created a class Student class that contains two data members Id, Name. Here, we implemented properties StudentId and StudentName to set values of data members, and implemented a PrintInfo() method to print values of data members on the console screen.

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 Student class and then set the values of data members using Properties and then print the student information using PrintInfo() method on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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

© https://www.includehelp.com some rights reserved.