Structure overrides ToString method : Structure « Language Basics « 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 » Language Basics » StructureScreenshots 
Structure overrides ToString method
 
Imports System

Public Class MainClass
    
    Shared Sub Main()
        Dim loc1 As Location  
        loc1.XVal = 75
        loc1.YVal = 225

        ' display the values in the structure
        Console.WriteLine("Loc1 location: {0}", loc1)
    End Sub
End Class

      Public Structure Location
         Private myXVal As Integer
         Private myYVal As Integer

         Public Sub New_
            ByVal xCoordinate As Integer, ByVal yCoordinate As Integer)
             myXVal = xCoordinate
             myYVal = yCoordinate
         End Sub 'New

         Public Property XVal(  ) As Integer
             Get
                 Return myXVal
             End Get
             Set(ByVal Value As Integer)
                 myXVal = Value
             End Set
         End Property

         Public Property YVal(  ) As Integer
             Get
                 Return myYVal
             End Get
             Set(ByVal Value As Integer)
                 myYVal = Value
             End Set
         End Property

         Public Overrides Function ToString(  ) As String
             Return String.Format("{0}, {1}", XVal, YVal)
         End Function 
     End Structure 
           
         
  
Related examples in the same category
1.Structure Variable assignment
2.ToString Method for Structure data typeToString Method for Structure data type
3.Structure with Constructor
4.Store Structure into a Collection
5.Compare Structure and ClassCompare Structure and Class
6.Pass Structure into a FunctionPass Structure into a Function
7.Simple Structure DemoSimple Structure Demo
8.ValueType.Equals Method Indicates whether this instance and a specified object are equal.
ww_w___.__j__a___v__a___2s___.__c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.