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

Home
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.LINQ
13.Network Remote
14.Thread
15.Windows Presentation Foundation
16.Windows System
17.XML
18.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
ww_w.j___av__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.