Csharp/CSharp Tutorial/Class/Hash Code

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Override the GetHashCode method from object

<source lang="csharp">using System; public sealed class ComplexNumber {

   public ComplexNumber( double real, double imaginary ) {
       this.real = real;
       this.imaginary = imaginary;
   }
   public override int GetHashCode() {
       return (int) Math.Sqrt( Math.Pow(this.real, 2) * Math.Pow(this.imaginary, 2) );
   }
   private readonly double real;
   private readonly double imaginary;

}</source>