Generic Point Structure : Generic Class « Generics « 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 » Generics » Generic ClassScreenshots 
Generic Point Structure
  


Option Explicit On
Option Strict On

Module Program
  Sub Main()
    Dim intPt As New Point(Of Integer)(100100)
    Console.WriteLine(intPt.ToString())
    Dim dblPt As New Point(Of Double)(5.63.23)
    Console.WriteLine(dblPt.ToString())
    Dim p1 As New Point(Of Integer)(1043)
    Dim p2 As New Point(Of Integer)(6987)
    Console.WriteLine(p1)
    Console.WriteLine(p2)
    Swap(Of Point(Of Integer))(p1, p2)
    Swap(p1, p2)
    Console.WriteLine(p1)
    Console.WriteLine(p2)

  End Sub
  Public Function Swap(Of T)(ByRef a As T, ByRef b As TAs T
    Console.WriteLine("T is a {0}.", GetType(T))
    Dim temp As T
    temp = a
    a = b
    b = temp
  End Function
End Module

Public Structure Point(Of T)
  Private xPos, yPos As T

  Public Sub New(ByVal x As T, ByVal y As T)
    xPos = x : yPos = y
  End Sub
  Public Property X() As T
    Get
      Return xPos
    End Get
    Set(ByVal value As T)
      xPos = value
    End Set
  End Property
  Public Property Y() As T
    Get
      Return xPos
    End Get
    Set(ByVal value As T)
      yPos = value
    End Set
  End Property
  Public Overrides Function ToString() As String
    Return String.Format("({0}, {1})", xPos, yPos)
  End Function
End Structure

   
    
  
Related examples in the same category
1.Generic List stores Generic ClassGeneric List stores Generic Class
2.Generic Class DemoGeneric Class Demo
3.Declare a generic type
w_w__w___.___ja___v_a___2_s___.c__om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.