// Базовый класс Object.
// Правило: Переопределяйте GetHashCode переопределяя Equals.
namespace ClassObject
{
{
protected int x, y;
public Point(int xValue,
int yValue
) {
x = xValue;
y = yValue;
}
public override bool Equals
(Object obj
) {
if (obj == null || GetType() != obj.GetType())
return false;
return (x == p.x) && (y == p.y);
}
public override int GetHashCode()
{
return x ^ y;
}
}
class Program
{
static void Main()
{
Console.WriteLine("a == b : {0}", a.Equals(b));
Console.WriteLine("a == c : {0}", a.Equals(c));
Console.WriteLine("a == b : {0}", Equals(a, b));
Console.WriteLine("a == c : {0}", Equals(a, c));
// Delay.
Console.ReadKey();
}
}
}
dXNpbmcgU3lzdGVtOwoKLy8g0JHQsNC30L7QstGL0Lkg0LrQu9Cw0YHRgSBPYmplY3QuCgovLyDQn9GA0LDQstC40LvQvjog0J/QtdGA0LXQvtC/0YDQtdC00LXQu9GP0LnRgtC1IEdldEhhc2hDb2RlINC/0LXRgNC10L7Qv9GA0LXQtNC10LvRj9GPIEVxdWFscy4KCm5hbWVzcGFjZSBDbGFzc09iamVjdAp7CiAgICBjbGFzcyBQb2ludCA6IG9iamVjdAogICAgewogICAgICAgIHByb3RlY3RlZCBpbnQgeCwgeTsKCiAgICAgICAgcHVibGljIFBvaW50KGludCB4VmFsdWUsIGludCB5VmFsdWUpCiAgICAgICAgewogICAgICAgICAgICB4ID0geFZhbHVlOwogICAgICAgICAgICB5ID0geVZhbHVlOwogICAgICAgIH0KCiAgICAgICAgcHVibGljIG92ZXJyaWRlIGJvb2wgRXF1YWxzKE9iamVjdCBvYmopCiAgICAgICAgewogICAgICAgICAgICBpZiAob2JqID09IG51bGwgfHwgR2V0VHlwZSgpICE9IG9iai5HZXRUeXBlKCkpCiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CgogICAgICAgICAgICBQb2ludCBwID0gKFBvaW50KW9iajsKICAgICAgICAgICAgcmV0dXJuICh4ID09IHAueCkgJiYgKHkgPT0gcC55KTsKICAgICAgICB9CgogICAgICAgIHB1YmxpYyBvdmVycmlkZSBpbnQgR2V0SGFzaENvZGUoKQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIHggXiB5OwogICAgICAgIH0KICAgIH0KCiAgICBjbGFzcyBQcm9ncmFtCiAgICB7CiAgICAgICAgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBQb2ludCBhID0gbmV3IFBvaW50KDEsIDIpOwogICAgICAgICAgICBQb2ludCBiID0gbmV3IFBvaW50KDEsIDIpOwogICAgICAgICAgICBQb2ludCBjID0gbmV3IFBvaW50KDAsIDApOwoKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoImEgPT0gYiA6IHswfSIsIGEuRXF1YWxzKGIpKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoImEgPT0gYyA6IHswfSIsIGEuRXF1YWxzKGMpKTsKCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJhID09IGIgOiB7MH0iLCBFcXVhbHMoYSwgYikpOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiYSA9PSBjIDogezB9IiwgRXF1YWxzKGEsIGMpKTsKCiAgICAgICAgICAgIC8vIERlbGF5LgogICAgICAgICAgICBDb25zb2xlLlJlYWRLZXkoKTsKICAgICAgICB9CiAgICB9Cn0=
Main.java:1: error: class, interface, or enum expected
using System;
^
Main.java:7: error: class, interface, or enum expected
namespace ClassObject
^
Main.java:9: error: '{' expected
class Point : object
^
Main.java:19: error: ';' expected
public override bool Equals(Object obj)
^
Main.java:19: error: invalid method declaration; return type required
public override bool Equals(Object obj)
^
Main.java:28: error: <identifier> expected
public override int GetHashCode()
^
Main.java:28: error: invalid method declaration; return type required
public override int GetHashCode()
^
Main.java:52: error: class, interface, or enum expected
}
^
8 errors