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
| //超市收銀系統
//產生一個不會重複的編號
Console.WriteLine(Guid.NewGuid());
/// <summary>
/// 商品的父類
/// </summary>
internal class ProductFather
{
public string ID { get; set; } //Guid.NewGuid()
public string Name { get; set; }
public decimal Price { get; set; }
public int Count { get; set; }
public ProductFather(string id, string name, decimal price, int count)
{
this.ID = id;
this.Name = name;
this.Price = price;
this.Count = count;
}
public ProductFather(string id, string name, decimal price)
: this(id, name, price, count: 0) //調用自己的構造函數
{
}
}
/// <summary>
/// Acer筆電
/// </summary>
internal class Acer : ProductFather
{
public Acer(string id, string name, decimal price)
: base(id, name, price) //調用父類的構造函數
{
}
}
/// <summary>
/// 三星
/// </summary>
internal class SamSung : ProductFather
{
public SamSung(string id, string name, decimal price)
: base(id, name, price)
{
}
}
/// <summary>
/// 醬油
/// </summary>
internal class Oil : ProductFather
{
public Oil(string id, string name, decimal price)
: base(id, name, price)
{
}
}
/// <summary>
/// 香蕉
/// </summary>
internal class Banana : ProductFather
{
public Banana(string id, string name, decimal price)
: base(id, name, price)
{
}
}
|