Posted by: Sourav | August 19, 2016

Properties Example in VB.Net,Sourav Bhattacharya


Module Module1

Sub Main()
Dim student1 As Student = New Student

Console.WriteLine(student1.manipulateid)
student1.manipulateid = 101

Console.WriteLine(student1.manipulateid)
Console.WriteLine(student1.manipulatename)
student1.manipulatename = “Subir”

Console.WriteLine(student1.manipulatename)
Console.WriteLine(student1.manipulatepassmark)

Console.ReadLine()

End Sub

End Module

 

 

Public Class Student
Private id As Integer
Private name As String
Private passmark As Integer = 35

Public Property manipulateid As Integer
Set(ByVal id As Integer)
If id <= 0 Then
Throw New Exception(“Student ID can not be negative”)

Else
Me.id = id
End If

End Set

Get
Return Me.id
End Get

End Property

Public Property manipulatename As String
Set(ByVal name As String)

‘ If String.IsNullOrWhiteSpace(Me.name) Then
‘Throw New Exception(“Student name can not be null or blank”)

‘Else
Me.name = name
‘End If

End Set

Get
Return IIf(String.IsNullOrWhiteSpace(Me.name), “No Name”, Me.name)

End Get

End Property
Public ReadOnly Property manipulatepassmark As Integer

Get
Return Me.passmark

End Get

End Property

End Class

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: