Object Class Supports all classes in the .NET Framework class hierarchy : Object « Development « 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 » Development » Object 




Object Class Supports all classes in the .NET Framework class hierarchy
  

Class Point
    Public x, y As Integer
    Public Sub New(ByVal x As Integer, ByVal y As Integer
        Me.x = x
        Me.y = y
    End Sub

    Public Overrides Function Equals(ByVal obj As ObjectAs Boolean 
        Dim objType As Type = obj.GetType()
        Dim meType  As Type = Me.GetType()
        If Not objType.Equals(meTypeThen
            Return False
        End If 
        Dim other As Point = CType(obj, Point)
        Return Me.x = other.x AndAlso Me.y = other.y
    End Function 

    Public Overrides Function GetHashCode() As Integer 
        Return x XOr y
    End Function 

    Public Overrides Function ToString() As String 
        Return String.Format("({0}, {1})", x, y)
    End Function

    Public Function Copy() As Point 
        Return CType(Me.MemberwiseClone(), Point)
    End Function
End Class  

Public Class App
    Shared Sub Main() 

        Dim p1 As New Point(12)
        Dim p2 As Point = p1.Copy()
        Dim p3 As Point = p1

        Console.WriteLine([Object].ReferenceEquals(p1, p2))
        Console.WriteLine([Object].Equals(p1, p2))
        Console.WriteLine([Object].ReferenceEquals(p1, p3))
        Console.WriteLine("p1's value is: {0}", p1.ToString())

    End Sub
End Class

   
    
  














Related examples in the same category
1.Object Class Supports all classes in the .NET Framework class hierarchy
2.Object.Equals Method tells whether the specified Object is equal to the current Object.
3.Create your own Equals method
4.Create Equals method based on Equals method from fields
5.Create Complex Structure with Equals and GetHashCode method
6.Object.GetType Method Gets the Type of the current instance.
7.Object.MemberwiseClone Method Creates a shallow copy of the current Object.
8.Object Class Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes.
9.Object.GetType Method Gets the Type of the current instance.
10.Object.MemberwiseClone Method Creates a shallow copy of the current Object.
11.Object.GetType Method Gets the Type of the current instance.
12.Object.MemberwiseClone Creates a shallow copy of the current Object.
13.No implementation. All members are inherited from Object
14.Overrides ToString function
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.