在我的表中有一个数据类型为时间戳的列。使用 Entity Framework 我可以获得这个时间戳值的值,它是一个 byte[] 值。
一旦将此值发送到 View ,它就会生成一个字符串值。 (我正在使用 Razor 引擎)
我的 byte[] 是 [0,0,0,0,0,1,159,44],一旦使用 Razor 将其转换为字符串,它就像 AAAAAAABnyw=
我的问题是这个字符串值是怎么变成这样的? Razor 使用的编码方式是什么?
如何使用 C# 从 byte[8] 中获取此字符串值?
最佳答案
What's the encoding method used by the razor?
嗯,这对我来说就像 Base64:
byte[] x = {0, 0, 0, 0, 0, 1, 159, 44};
Console.WriteLine(Convert.ToBase64String(x));
输出:AAAAAAABnyw=
您可以使用 Convert.FromBase64String
走另一条路。
或者,您可能想使用 BitConverter.ToInt64
检索原始 64 位整数 which corresponds to rowversion
,我相信。
关于c# - razor 如何将字节 [8] 转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28963749/