-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointIndexer.cs
More file actions
48 lines (44 loc) · 1.01 KB
/
Copy pathPointIndexer.cs
File metadata and controls
48 lines (44 loc) · 1.01 KB
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
using System;
class PointIndexer
{
private int x;
private int y;
public int this[int index]
{
get
{
if (index == 0)
return x;
else if (index == 1)
return y;
else
throw new IndexOutOfRangeException("Index must be 0 or 1.");
}
set
{
if (index == 0)
x = value;
else if (index == 1)
y = value;
else
throw new IndexOutOfRangeException("Index must be 0 or 1.");
}
}
public PointIndexer()
{
this.x = 0;
this.y = 0;
}
public PointIndexer(int x, int y)
{
this.x = x;
this.y = y;
}
static void Main()
{
PointIndexer p1 = new PointIndexer();
PointIndexer p2 = new PointIndexer(20, 10);
Console.WriteLine("Point 1: ({0}, {1})", p1[0], p1[1]);
Console.WriteLine("Point 2: ({0}, {1})", p2[0], p2[1]);
}
}