-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (77 loc) · 3.07 KB
/
Program.cs
File metadata and controls
111 lines (77 loc) · 3.07 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
namespace WK1ConsoleApp;
class Program
{
public static void LoopProductName(string[] productNames, string description = "Default description")
{
foreach (var product in productNames)
{
System.Console.WriteLine(product);
}
System.Console.WriteLine(description);
}
static void Main(string[] args)
{
string paintProductName = "Dulux";
string description = "";
string summary = "Summary: " + paintProductName + " and description is: " + description;
string summaryWithIntepolation = $"Summary: {paintProductName} and description is {description}";
System.Console.WriteLine(summary);
System.Console.WriteLine(summaryWithIntepolation);
int? noOfProducts = null;
int result = noOfProducts == null ? 0 : noOfProducts.Value;
int result2 = noOfProducts ?? 0;
bool hasValue = noOfProducts.HasValue;
if (hasValue)
{
System.Console.WriteLine(noOfProducts.Value);
}
int[] productPrices = { 100, 200, 300 };
string[] productNames = { "Dulux", "Nippon", "Basic" };
decimal productPrice = 100.05m;
double productPriceDouble = (double)productPrice;
int highSheenLevelPaintType = 1;
int lowSheenLevelPaintType = 2;
int basicSheenLevelPaintType = 3; //temp values, can not be reused!
PaintType duluxPaintType = PaintType.HighSheenLevelPaintType;
System.Console.WriteLine(duluxPaintType);
System.Console.WriteLine((int)duluxPaintType);
switch (duluxPaintType)
{
case PaintType.HighSheenLevelPaintType:
description = $"Dulux is type: {PaintType.HighSheenLevelPaintType}";
break;
case PaintType.LowSheenLevelPaintType:
description = $"Dulux is type: {PaintType.LowSheenLevelPaintType}";
break;
default:
description = "Dulux is type: Unknown";
break;
}
LoopProductName(productNames);
PaintProduct paintProduct = new PaintProduct()
{
Description = "3"
};
// 实例化的赋值
// 方法1: 先实例化, 再分别一行一行的赋值
// 方法2: 通过构造函数 赋值
// 方法3: 通过{} 赋值
//当这个对象被创建时, 他的构造函数 会被自动调用
// PaintProduct paintProduct2 = new PaintProduct("Dulux", 100, "Dulux Description")
// {
// Description = "3"
// };
//当这个对象被创建时, 他的构造函数 会被自动调用
//paintProduct is a instance of class PaintProduct
// paintProduct2.Description = "2";
paintProduct.DisplayProductInfo(); //报错, 因为这些值没有值
NipponPaint nipponPaint = new NipponPaint();
nipponPaint.DisplayProductInfo();
}
}
enum PaintType
{
HighSheenLevelPaintType = 101,
LowSheenLevelPaintType = 103,
BasicSheenLevelPaintType = 105
} //Camel Case