Properties

Unknown | 1:44 AM |

Properties are named members of classes, structs, and interfaces. They provide a flexible
mechanism to read, write, or compute the values of private fields through accessors.
Properties are an extension of fields and are accessed using the same syntax. Unlike
fields, properties do not designate storage locations. Instead, properties have accessors
that read, write, or compute their values.

Get accessor
The execution of the get accessor is equivalent to reading the value of the field.
The following is a get accessor that returns the value of a private field name:
Dim name as String ’ the name field
Property Name() As String ’ the name property
Get
Return name
End Get
End Property

Set accessor

The set accessor is similar to a method that returns void. It uses an implicit parameter
called value, whose type is the type of the property. In the following example, a set
accessor is added to the Name property:
Dim name as String ’ the name field
Property Name() As String ’ the name property
Get
Return name

End Get
Set(ByVal Value As String)
Name = value
End Set
End Property
When you assign a value to the property, the set accessor is invoked with an argument
that provides the new value. For example:
e1.Name = "Reshmi" // The set accessor is invoked here
It is an error to use the implicit parameter name (value) for a local variable declaration in
a set accessor.
How to make a Property Read Only/Write Only
There are times when we may want a property to be read-only – such that it can’t be
changed. This is where read-only properties come into the picture. A Read Only property
is one which includes only the get accessor, no set accessor.

For instance,
Public ReadOnly Property EmpID() as Integer
Get
Return empid
End Get
End Property
Similar to read-only properties there are also situations where we would need something
known as write-only properties. In this case the value can be changed but not retrieved.
To create a write-only property, use the WriteOnly keyword and only implement the set
block in the code as shown in the example below.
Public WriteOnly Property e as string
Set
e = Value
End Set
End Property

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....