mam podsumować moje pytanie w następujący kod snippetJaka jest różnica między GetHashCode zaimplementowanym w klasie Object i ValueType?
struct Point
{
public int X;
public int Y;
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public void PrintValue()
{
Console.WriteLine(
"{0},{1}",
this.X, this.Y);
}
}
powyżej struktury pochodzi z ValueType która zawiera metodę GetHashCode. Poniżej znajduje się wersja klasy wywodząca się z Object i zawierająca metodę GetHashCode
.
class Point
{
public int X;
public int Y;
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public void PrintValue()
{
Console.WriteLine(
"{0},{1}",
this.X, this.Y);
}
}
Chciałem tylko wiedzieć. Czy jest jakaś różnica między tymi implementacjami?
Marc Gravell: +1 i dzięki za szczegółowe wyjaśnienie :) –