【问题标题】:Out of Range Exception with DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks [closed]DateTime.MinValue.Ticks 和 DateTime.MaxValue.Ticks 超出范围异常 [关闭]
【发布时间】:2021-01-07 15:59:06
【问题描述】:

为什么我得到这个超出范围的异常,我在框架 4.7 中使用了相同的逻辑并且从未遇到过这个问题。它现在在 4.8 上运行,是与此有关还是我在这里遗漏了什么。请有人给我解释一下。

pressureChart.AxisX.Add(new Axis
            {
                DisableAnimations = true,
                LabelFormatter = value => new System.DateTime((long)value).ToString("mm:ss"), // Exception Here
                Separator =  new Separator
                {
                    Step = TimeSpan.FromSeconds(10).Ticks
                }
            });

例外

System.ArgumentOutOfRangeException: 'Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
Parameter name: ticks'

【问题讨论】:

  • value的值是多少?

标签: c# .net timespan livecharts


【解决方案1】:
Console.WriteLine(DateTime.MinValue.Ticks);  // =>  0
Console.WriteLine(DateTime.MaxValue.Ticks);  // =>  3155378975999999999
Console.WriteLine(long.MinValue);            // => -9223372036854775808
Console.WriteLine(long.MaxValue);            // =>  9223372036854775807

在最近的版本中,这些限制都没有改变,所以看起来,到目前为止你没有任何例外,只是幸运或在计算你的 value 时发生了一些变化。无论如何它可以得到负面的? (意外或有意)

【讨论】:

    猜你喜欢
    • 2013-10-19
    • 2014-11-12
    • 2014-03-06
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多