-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStruct_box_unbox.cs
More file actions
64 lines (47 loc) · 1.51 KB
/
Struct_box_unbox.cs
File metadata and controls
64 lines (47 loc) · 1.51 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
namespace Core
{
public interface IChangePoint
{
void Change(int x, int y);
}
public struct Point : IChangePoint
{
private int _x;
private int _y;
public Point(int x, int y) { _x = x; _y = y; }
public void Change(int x, int y) { _x = x; _y = y; }
public override string ToString() => $"({_x}, {_y})";
}
public class CurrentInfo
{
public CurrentInfo(Point point) { CurrentPoint = point; }
public Point CurrentPoint { get; }
}
public sealed class Program
{
public static void Main()
{
var info = new CurrentInfo(new Point(1, 1));
ChangeCurrentPoint(info);
Console.WriteLine($"Final result: {info.CurrentPoint}");
}
public static void ChangeCurrentPoint(CurrentInfo info)
{
Point p = info.CurrentPoint;
Console.WriteLine($"1) {p}");
p.Change(2, 2);
Console.WriteLine($"2) {p}");
object o = p;
Console.WriteLine($"3) {o}");
((Point)o).Change(3, 3);
Console.WriteLine($"4) {o}");
((IChangePoint)p).Change(4, 4);
Console.WriteLine($"5) {p}");
((IChangePoint)o).Change(5, 5);
Console.WriteLine($"6) {o}");
info.CurrentPoint.Change(-10, -10);
Console.WriteLine($"7) {info.CurrentPoint}");
}
}
}