C# GetHashCode
In this chapter you will learn:
Hash code
Hash code is used by C# to distinguish one object from another. If two object represent two difference value they should have different hash code value.
Example
Example for GetHashCode Method
using System;// w w w. jav a2 s. c o m
public 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;
}
Next chapter...
What you will learn in the next chapter: