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.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.