-
Notifications
You must be signed in to change notification settings - Fork 1
/
Point.cs
60 lines (49 loc) · 1.41 KB
/
Point.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Point : IComparable<Point>
{
// Auto-implemented properties
public int X { get; set; }
public int Y { get; set; }
public int CompareTo(Point other)
{
if (this.X == other.X)
if (this.Y == other.Y)
return 0;
else
return this.Y - other.Y;
else
return this.X - other.X;
}
public override bool Equals(object obj)
{
Point other = obj as Point; // Downcasting (base to derived)
return this.X == other.X && this.Y == other.Y;
}
public override string ToString()
{
return X + "," + Y;
}
}
class TestPoint
{
static void Main(string[] args)
{
String s1 = "Abcd";
String s2 = "Xyz";
Console.WriteLine(s1.Equals(s2));
Console.WriteLine(s1.CompareTo(s2));
Point p1 = new Point { X = 10, Y = 40 };
Point p2 = new Point { X = 10, Y = 30 };
Console.WriteLine(p1 == p2);
Console.WriteLine(p1.Equals(p2));
Console.WriteLine(p1.ToString());
Console.WriteLine(p1.CompareTo(p2));
}
}
}