Define and use Interface Age : Interface « Class « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Class » InterfaceScreenshots 
Define and use Interface Age
Define and use Interface Age

Imports System
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
      Dim person As New CPerson("A""B"1983)

      Dim iAgeArray As IAge() = New IAge(1) {}

      iAgeArray(0= person
      iAgeArray(1= New CPerson("C""D"1999)

      Console.WriteLineperson.ToString() ": " & _
         person.Name & vbCrLf & "Age is " & person.Age )

      Dim ageReference As IAge

      For Each ageReference In iAgeArray
         Console.WriteLineageReference.Name & ": " & _
            "Age is " & ageReference.Age )
      Next
    End Sub
End Class


Public Interface IAge
   ReadOnly Property Age() As Integer
   ReadOnly Property Name() As String

End Interface

Public Class CPerson
   Implements IAge

   Private mYearBorn As Integer
   Private mFirstName As String
   Private mLastName As String

   Public Sub New(ByVal firstNameValue As String, _
      ByVal lastNameValue As String, _
      ByVal yearBornValue As Integer)

      mFirstName = firstNameValue
      mLastName = lastNameValue

      If (yearBornValue > AndAlso _
         yearBornValue <= Date.Now.YearThen

         mYearBorn = yearBornValue
      Else
         mYearBorn = Date.Now.Year
      End If

   End Sub

   ReadOnly Property Age() As Integer _
      Implements IAge.Age

      Get
         Return Date.Now.Year - mYearBorn
      End Get

   End Property

   ReadOnly Property Name() As String _
      Implements IAge.Name
      Get
         Return mFirstName & " " & mLastName
      End Get
   End Property

End Class
           
       
Related examples in the same category
1.One Class implements two Interfaces which have the same name methodOne Class implements two Interfaces which have the same name method
2.Interface inherits interfaceInterface inherits interface
3.Class implements two interfaces
4.Implements an InterfaceImplements an Interface
5.Implement an InterfaceImplement an Interface
6.Interface Inherits another InterfaceInterface Inherits another Interface
7.Define and use InterfaceDefine and use Interface
8.Implements Two InterfacesImplements Two Interfaces
9.Generic Class and InterfaceGeneric Class and Interface
w___w__w.___j_a___v___a___2_s___._c___o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.