Working with VB.Net Properties

Rajesh_Kumar
Posted by Rajesh_Kumar under VB.NET category on | Points: 40 | Views : 626
Although properties are same in both VB.Net and C# but syntax differs.

Public Class Project_Master
Private _project_name As String
Private _project_id As Integer

Public Property Project_Name() As String
Get
Return _project_name
End Get
Set(ByVal value As String)
_project_name = value
End Set
End Property

Public Property Project_ID() As Integer
Get
Return _project_id
End Get
Set(ByVal value As Integer)
_project_id = value
End Set
End Property
End Class

'Now in another class
Dim prj_obj As New Project_Master

'setting/assigning properties
prj_obj.Project_ID = 1
prj_obj.Project_Name = "ABC"

'getting/accessing properties
Dim prj_id As Integer = prj_obj.Project_ID
Dim prj_name As String = prj_obj.Project_Name

Comments or Responses

Login to post response