小编Ben*_*enj的帖子

使用 System.Text.Json 反序列化 Json 时间戳

我正在尝试反序列化以下 JSON

{"serverTime":1613967667240}
Run Code Online (Sandbox Code Playgroud)

进入以下类的对象

public class ApiServerTime
{
    [JsonPropertyName("serverTime")]
    public DateTime ServerTime
    {
        get;
        private set;
    }
}
Run Code Online (Sandbox Code Playgroud)

使用以下命令:

JsonSerializer.Deserialize<ApiServerTime>(jsonString);
Run Code Online (Sandbox Code Playgroud)

但生成的对象包含ServerTime == DateTime.MinValue. 我究竟做错了什么?

c# datetime json system.text.json

6
推荐指数
2
解决办法
5514
查看次数

gcc 版本 4、5 和 6 之间的差异

在下载arm交叉编译器的源代码时,我发现维护中有多个版本的 gcc。最新版本是 v4.9.4、v5.4.0 和 v6.2.0。

为什么 v4 比 v5 的最新版本和 v6 的第一个版本更新,这些版本之间的主要区别是什么?

GNU GCC 存储库

c c++ gcc

5
推荐指数
1
解决办法
7549
查看次数

在堆栈上创建固定大小的数组

我需要一个固定的数据结构(出于性能原因)在堆栈上管理,但行为类似于数组

我知道我可以创建这样的东西:

using System;

namespace X
{
    public sealed struct CustomArray<T>
    {
        private const Int32 n = 2;

        private T _field_1;
        private T _field_2;
        // ...
        private T _field_n;

        public T this[Int32 idx]
        {
            get
            {
                switch(idx)
                {
                    case (0): return _field_1;
                    case (1): return _field_2;
                    // ...
                    case (n): return _field_n;

                    default: throw new IndexOutOfRangeException();
                }
            }
            set
            {
                switch(idx)
                {
                    case (0): _field_1 = value; break;
                    case (1): _field_2 = value; break;
                    // ...
                    case (n): _field_n = …
Run Code Online (Sandbox Code Playgroud)

c# arrays stack

4
推荐指数
1
解决办法
2717
查看次数

tput setf 的颜色代码

我正在寻找包含此内容的文件

export fgBlack8="$(tput setf 0)";
export fgRed8="$(tput setf 1)";
export fgGreen8="$(tput setf 2)";
export fgYellow8="$(tput setf 3)";
export fgBlue8="$(tput setf 4)";
export fgMagenta8="$(tput setf 5)";
export fgCyan8="$(tput setf 6)";
export fgWhite8="$(tput setf 7)";

export bgBlack8="$(tput setb 0)";
export bgRed8="$(tput setb 1)";
export bgGreen8="$(tput setb 2)";
export bgYellow8="$(tput setb 3)";
export bgBlue8="$(tput setb 4)";
export bgMagenta8="$(tput setb 5)";
export bgCyan8="$(tput setb 6)";
export bgWhite8="$(tput setb 7)";
Run Code Online (Sandbox Code Playgroud)

根据此链接:https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/

然后,当用这样的几个命令测试颜色时

echo -e "${fgBlack8}fgBlack8"
echo -e "${fgRed8}fgRed8"
echo -e "${fgGreen8}fgGreen8"
echo -e "${fgYellow8}fgYellow8" …
Run Code Online (Sandbox Code Playgroud)

bash shell terminfo tput

4
推荐指数
1
解决办法
8090
查看次数

为什么 System.Text.Json 的 JSON 反序列化如此慢?

我有一个同样的最小项目,用 C# 和 Go 编写,将 json 反序列化 100,000 次。性能差异很大。虽然很高兴知道可以通过使用 Go 来实现性能目标,但我更愿意在 C# 中实现类似的结果。鉴于 C# 慢了 193 倍,我认为错误在我这边,但我不明白为什么。

表现

$ dotnet run .
real    1m37.555s
user    1m39.552s
sys     0m0.729s

$ ./jsonperf
real    0m0.478s
user    0m0.500s
sys     0m0.011s
Run Code Online (Sandbox Code Playgroud)

源代码 C#

using System;

namespace jsonperf
{
    class Program
    {
        static void Main(string[] args)
        {
            var json = "{\"e\":\"trade\",\"E\":1633046399882,\"s\":\"BTCBUSD\",\"t\":243216662,\"p\":\"43818.22000000\",\"q\":\"0.00452000\",\"b\":3422298876,\"a\":3422298789,\"T\":1633046399882,\"m\":false,\"M\":true}";

            for (int i = 0; i < 100000; i++)
            {
                if (0 == i % 1000)
                {
                    Console.WriteLine($"Completed: {i}");
                }

                var obj = BinanceTradeUpdate.FromJson(json);
            } …
Run Code Online (Sandbox Code Playgroud)

c# json go .net-core system.text.json

2
推荐指数
1
解决办法
2949
查看次数

标签 统计

c# ×3

json ×2

system.text.json ×2

.net-core ×1

arrays ×1

bash ×1

c ×1

c++ ×1

datetime ×1

gcc ×1

go ×1

shell ×1

stack ×1

terminfo ×1

tput ×1