回答編集履歴
2
修正
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
なお `new byte[32]` については恐らくバッファを確保するつもりだっただけだと見てどちらのソースでも無視しています。
|
68
68
|
|
69
|
-
必要であれば上のソースでは `ret.AddRange(new byte[32])` 下のソースは `.Concat()` を使って追加できます。
|
69
|
+
必要であれば上のソースでは `ret.AddRange(new byte[32])` 下のソースは `Enumerable.Repeat((byte)0, 32).Concat()` を使って追加できます。
|
70
70
|
|
71
71
|
|
72
72
|
|
1
追記
test
CHANGED
@@ -57,3 +57,53 @@
|
|
57
57
|
}
|
58
58
|
|
59
59
|
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
###追記
|
64
|
+
|
65
|
+
特に意味はありませんが、LINQ と C#7 の新機能である型スイッチを使った方法です。
|
66
|
+
|
67
|
+
なお `new byte[32]` については恐らくバッファを確保するつもりだっただけだと見てどちらのソースでも無視しています。
|
68
|
+
|
69
|
+
必要であれば上のソースでは `ret.AddRange(new byte[32])` 下のソースは `.Concat()` を使って追加できます。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
```C#
|
74
|
+
|
75
|
+
byte[] toByte()
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
return dictionary
|
80
|
+
|
81
|
+
.SelectMany<KeyValuePair<string, object>, byte>(x =>
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
switch (x.Value)
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
case null:
|
90
|
+
|
91
|
+
return Enumerable.Empty<byte>();
|
92
|
+
|
93
|
+
case string value:
|
94
|
+
|
95
|
+
return System.Text.Encoding.ASCII.GetBytes(value);
|
96
|
+
|
97
|
+
default:
|
98
|
+
|
99
|
+
return BitConverter.GetBytes((dynamic)x.Value);
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
})
|
104
|
+
|
105
|
+
.ToArray();
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
```
|