回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,59 +1,30 @@
|
|
1
1
|
`return $"{dt:yyyy年}";`が一番スッキリしてるんじゃないですかね。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
```
|
3
|
+
```cs
|
6
|
-
|
7
4
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
8
|
-
|
9
5
|
using System;
|
10
6
|
|
11
|
-
|
12
|
-
|
13
7
|
namespace Questions323920
|
14
|
-
|
15
8
|
{
|
16
|
-
|
17
9
|
class A
|
18
|
-
|
19
10
|
{
|
20
|
-
|
21
11
|
public static string GetDisplayYear(DateTime? dt)
|
22
|
-
|
23
12
|
{
|
24
|
-
|
25
13
|
return $"{dt:yyyy年}";
|
26
|
-
|
27
14
|
//return dt?.ToString("yyyy年") ?? "";
|
28
|
-
|
29
15
|
//return dt.HasValue ? dt?.Year + "年" : "";
|
30
|
-
|
31
16
|
}
|
32
|
-
|
33
17
|
}
|
34
18
|
|
35
|
-
|
36
|
-
|
37
19
|
[TestClass()]
|
38
|
-
|
39
20
|
public class ATests
|
40
|
-
|
41
21
|
{
|
42
|
-
|
43
22
|
[TestMethod()]
|
44
|
-
|
45
23
|
public void GetDisplayYearTest()
|
46
|
-
|
47
24
|
{
|
48
|
-
|
49
25
|
Assert.AreEqual("2021年", A.GetDisplayYear(DateTime.Parse("2021/02/21 23:00:00")));
|
50
|
-
|
51
26
|
Assert.AreEqual("", A.GetDisplayYear(null));
|
52
|
-
|
53
27
|
}
|
54
|
-
|
55
28
|
}
|
56
|
-
|
57
29
|
}
|
58
|
-
|
59
30
|
```
|