×

VB.Net Programs

VB.Net program to implement WriteOnly property

By Nidhi Last Updated : November 15, 2024

How to implement WriteOnly property in VB.Net?

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 code to implement WriteOnly property

'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 »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.