VB.NET tutorial-Class Properties

Object-Oriented Programming (OOP)

Class Properties

Properties are member of the class that can be used to access its private data. You will use the Get and Set keywords to specify that a propery is readable and writable. If you use only the Get keyword, the property is read-only. When the property is read-only, you only can read the content of private member variable. But you can not assign a value to that variable. If you use only the Set keyword the property is write-only. You can assign a value to the private member variable. However, you can not read that value back.

Class Animal
        Private numberOflegs As Integer
        'defining property numberlegs with Get and Set Keywords
        'Note:Use Get keyword to make the property readable
        'Use Set keyword to make the property writable
         'Use only Get and ReadOnly keywords or Set with WriteOnly
         'keywords if you want the property readable only
        'or writable only
        'The keyword ReadOnly and WriteOnly must be put before
        'Property keyword
        Public Property numberlegs() As Integer
                Return numberOflegs
            End Get
            Set(ByVal value As Integer)
                numberOflegs = value
            End Set
        End Property
    End Class


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.