Class Property Get and Set : Property « Class « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
VB.Net » Class » PropertyScreenshots 
Class Property Get and Set
Class Property Get and Set

Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
      Dim time As New CTime3()
      ' invoke time6 methods

      time.Second = (time.Second + 1)

      time.Minute = (time.Minute + 1)
      time.Hour = (time.Hour + 1)

      
      Console.WriteLine(  "Hour: " & time.Hour & "; Minute: " & _
         time.Minute & "; Second: " & time.Second )
    End Sub
End Class


' Represents time in 24-hour format and contains properties.

Class CTime3
   Inherits Object

   ' declare Integers for hour, minute and second
   Private mHour As Integer
   Private mMinute As Integer
   Private mSecond As Integer

   ' CTime3 constructor: initialize each instance variable to zero
   ' and ensure that each CTime3 object starts in consistent state
   Public Sub New()
      SetTime(000)
   End Sub ' New

   ' CTime3 constructor: 
   ' hour supplied, minute and second defaulted to 0
   Public Sub New(ByVal hourValue As Integer)
      SetTime(hourValue, 00)
   End Sub ' New

   ' CTime3 constructor: 
   ' hour and minute supplied; second defaulted to 0
   Public Sub New(ByVal hourValue As Integer, _
      ByVal minuteValue As Integer)

      SetTime(hourValue, minuteValue, 0)
   End Sub ' New

   ' CTime3 constructor: hour, minute and second supplied
   Public Sub New(ByVal hourValue As Integer, _
      ByVal minuteValue As Integer, ByVal secondValue As Integer)

      SetTime(hourValue, minuteValue, secondValue)
   End Sub ' New

   ' CTime3 constructor: another CTime3 object supplied
   Public Sub New(ByVal timeValue As CTime3)
      SetTime(timeValue.mHour, timeValue.mMinute, _
         timeValue.mSecond)
   End Sub ' New

   ' set new time value using universal time;
   ' uses properties to perform validity checks on data
   Public Sub SetTime(ByVal hourValue As Integer, _
      ByVal minuteValue As Integer, ByVal secondValue As Integer)

      Hour = hourValue     ' looks
      Minute = minuteValue ' dangerous
      Second = secondValue ' but it is correct
   End Sub ' SetTime

   ' property Hour
   Public Property Hour() As Integer

      ' return mHour value
      Get
         Return mHour
      End Get

      ' set mHour value
      Set(ByVal value As Integer)

         If (value >= AndAlso value < 24Then
            mHour = value
         Else
            mHour = 0
         End If

      End Set

   End Property ' Hour

   ' property Minute
   Public Property Minute() As Integer

      ' return mMinute value
      Get
         Return mMinute
      End Get

      ' set mMinute value
      Set(ByVal value As Integer)

         If (value >= AndAlso value < 60Then
            mMinute = value
         Else
            mMinute = 0
         End If

      End Set

   End Property ' Minute

   ' property Second
   Public Property Second() As Integer

      ' return mSecond value
      Get
         Return mSecond
      End Get

      ' set mSecond value
      Set(ByVal value As Integer)

         If (value >= AndAlso value < 60Then
            mSecond = value
         Else
            mSecond = 0
         End If

      End Set

   End Property ' Second

End Class 
           
       
Related examples in the same category
1. Declare Protected Properties
2. Shared Property DemoShared Property Demo
3. Get and set PropertiesGet and set Properties
4. Property Shadow during InheritanceProperty Shadow during Inheritance
5. Define and use Class: PropertyDefine and use Class: Property
w__w___w__.___j__av__a_2s_.__c___o__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.