Reference type equals: complex number : Object Reference « Class « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Class » Object Reference 
7.3.8.Reference type equals: complex number
public class ComplexNumber
{
   public ComplexNumberint real, int imaginary )
   {
      this.real = real;
      this.imaginary = imaginary;
   }

   public override bool Equalsobject obj )
   {
      ComplexNumber other = obj as ComplexNumber;

      ifother == null )
      {
         return false;
      }

      return (this.real == other.real&& (this.imaginary == other.imaginary);
   }

   public override int GetHashCode()
   {
      return (intreal ^ (intimaginary;
   }

   public static bool operator==ComplexNumber me, ComplexNumber other )
   {
      return Equalsme, other );
   }

   public static bool operator!=ComplexNumber me, ComplexNumber other )
   {
      return Equalsme, other );
   }
   
   private double real;
   private double imaginary;
}

public class MainClass
{
   static void Main()
   {
      ComplexNumber referenceA = new ComplexNumber1);
      ComplexNumber referenceB = new ComplexNumber1);

      System.Console.WriteLine"Result of Equality is {0}",referenceA == referenceB );

      System.Console.WriteLine"Identity of references is {0}",(objectreferenceA == (objectreferenceB );
      System.Console.WriteLine"Identity of references is {0}",ReferenceEquals(referenceA, referenceB) );
   }
}
Result of Equality is True
Identity of references is False
Identity of references is False
7.3.Object Reference
7.3.1.Declare class fields and methods
7.3.2.Declare a House object reference named myHouse
7.3.3.Creating a House object and assigning its memory location to myHouse
7.3.4.Assign values to the House object's fields using object renerence
7.3.5.Display the field values using object reference
7.3.6.Declare another House object reference and create another House object
7.3.7.Change the object referenced by the myHouse object reference to the object referenced by yourHouse
7.3.8.Reference type equals: complex number
7.3.9.Reference equals
7.3.10.Reference a static member function without using the class name
7.3.11.Overridden Equals()
7.3.12.Reference an object by interface and class
7.3.13.Pass reference type variable without 'out' and 'ref'
7.3.14.Use interface as reference
7.3.15.Reference one object by multiple interfaces
7.3.16.Class comparison
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.