Override ToString function : ToString « 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
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » Class » ToStringScreenshots 
Override ToString function
Override ToString function

Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
      Dim point As Point

      point = New Point(72115' instantiate Point object

      ' display point coordinates via X and Y properties
      Console.WriteLine"X coordinate is " & point.X & _
         vbCrLf & "Y coordinate is " & point.Y )

      point.X = 10 ' set x-coordinate via X property
      point.Y = 10 ' set y-coordinate via Y property

      ' display new point value
      Console.WriteLine("The new location of point is " & point.ToString() )

    End Sub
End Class

' Point class represents an x-y coordinate pair.

Public Class Point
   ' implicitly Inherits Object

   Private mX, mY As Integer

   Public Sub New()
      ' implicit call to Object constructor occurs here
      X = 0
      Y = 0
   End Sub ' New

   ' constructor
   Public Sub New(ByVal xValue As Integer,ByVal yValue As Integer)
      ' implicit call to Object constructor occurs here
      X = xValue
      Y = yValue
   End Sub ' New

   ' property X
   Public Property X() As Integer
      Get
         Return mX
      End Get

      Set(ByVal xValue As Integer)
         mX = xValue ' no need for validation
      End Set

   End Property ' X

   ' property Y 
   Public Property Y() As Integer

      Get
         Return mY
      End Get

      Set(ByVal yValue As Integer)
         mY = yValue ' no need for validation
      End Set

   End Property ' Y

   ' return String representation of Point
   Public Overrides Function ToString() As String
      Return "[" & mX & ", " & mY & "]"
   End Function ' ToString

End Class 
           
       
Related examples in the same category
1. Override Object.ToStringOverride Object.ToString
2. Override ToString Method to provide meaningful informationOverride ToString Method to provide meaningful information
w_w__w.j___a_v___a2___s.__c__om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.