This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18052|Reply: 0

[Source] Because <null>there is no implicit conversion between and System.DateTime

[Copy link]
Posted on 11/3/2015 4:13:48 PM | | |
The type of conditional expression cannot be determined because there <null>is no implicit conversion between "" and "System.DateTime" ---- workaround


When using nullable types in C#, pay attention to the consistency between types, and the above problem of not being able to convert with DateTime is that you do not pay attention to the consistency between types, for example, when assigning a value to a nullable time type field, you cannot use null, but you want to use a DateTime? Type.

Example: (Error)

public DateTime? time { get; set; }

time = item. HospOutDate.HasValue ? DateTime.Parse(item. HospOutDate.Value.ToString("yyyy-MM-dd HH:mm:ss")) : null;

Error message: The type of conditional expression cannot be determined because there <null>is no implicit conversion between "" and "System.DateTime"



Solution:

Added: DateTime? TimeNull = null;

time = item. HospOutDate.HasValue ? DateTime.Parse(item. HospOutDate.Value.ToString("yyyy-MM-dd HH:mm:ss")) : TimeNull ;

Solution:

Declared DateTime before? TimeNull = null;
Then site. UpdateTime = dr["UpdateTime"]. ToString(). Equals("") ? TimeNull : Convert.ToDateTime(dr["UpdateTime"]);





Previous:Jquery dataTable dynamically loads data for ajax requests
Next:Regarding ternary operators, there is an error that cannot determine the type of conditional expression
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com