-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathIDumpable.cs
More file actions
84 lines (73 loc) · 1.41 KB
/
IDumpable.cs
File metadata and controls
84 lines (73 loc) · 1.41 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
interface IDumpable
{
string Name { get; set; }
void Dump();
}
class Fraction : IDumpable
{
int z, n;
string name;
public Fraction(int z, int n)
{
this.z = z;
this.n = n;
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public void Dump()
{
Console.WriteLine("Fraction : " + z + "/" + n);
}
}
class Person : IDumpable
{
string name;
public string address;
public int phone;
public Person(string name, string address, int phone)
{
this.name = name;
this.address = address;
this.phone = phone;
}
public string Name
{
get { return name; }
set { name = value; }
}
public void Dump()
{
Console.WriteLine("Person Details : {0}, {1}, {2}", name, address, phone);
}
}
class Test
{
static void Main(string[] arg)
{
IDumpable[] a =
{
new Fraction(10,3),
new Fraction(9,4),
new Person("Tom", "Japan", 99556677),
new Person("Jerry", "Japan", 998979899),
};
a[0].Name = "f1";
a[1].Name = "f2";
foreach (IDumpable obj in a)
{
Console.Write(obj.Name + ": ");
obj.Dump();
}
Console.ReadLine();
}
}