gpt4 book ai didi

c# - 即时窗口 - 转换为日期时间?抛出异常但 (datetime) 没有

转载 作者:可可西里 更新时间:2023-11-01 07:59:02 24 4
gpt4 key购买 nike

直接取自即时窗口:

reader["DateDue"] as DateTime?产量:

'reader["DateDue"] as DateTime?' threw an exception of type 'System.NullReferenceException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147467261
HelpLink: null
InnerException: null
Message: "Object reference not set to an instance of an object."
Source: null
StackTrace: null
TargetSite: null

(DateTime?)reader["DateDue"]产量:

{1/26/2015 12:00:00 AM}
Date: {1/26/2015 12:00:00 AM}
Day: 26
DayOfWeek: Monday
DayOfYear: 26
Hour: 0
Kind: Unspecified
Millisecond: 0
Minute: 0
Month: 1
Second: 0
Ticks: 635578272000000000
TimeOfDay: {System.TimeSpan}
Year: 2015

作为引用,reader["DateDue"]产量:

{1/26/2015 12:00:00 AM}
Date: {1/26/2015 12:00:00 AM}
Day: 26
DayOfWeek: Monday
DayOfYear: 26
Hour: 0
Kind: Unspecified
Millisecond: 0
Minute: 0
Month: 1
Second: 0
Ticks: 635578272000000000
TimeOfDay: {00:00:00}
Year: 2015

这是一个错误吗?如果直接转换到DateTime?然后用 as DateTime? 类型转换也应该有效。

我确实通过使用 reader.GetDateTime(reader.GetOrdinal("DateDue")) as DateTime? 找到了解决此问题的方法. 没关系,它不能很好地处理空值。无论如何,有无数种方法可以解决这个奇怪的问题。

演示该问题的 repo 可以在这里找到:https://github.com/jjoedouglas/exceptionAsDatetime

最佳答案

这似乎是 VS2015 即时窗口中的错误。

关于c# - 即时窗口 - 转换为日期时间?抛出异常但 (datetime) 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31644977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com