Is there a difference between a ternary operator and an if statement in C#? [duplicate]
问题 This question already has answers here : Nullable types and the ternary operator: why is `? 10 : null` forbidden? [duplicate] (9 answers) Conditional operator cannot cast implicitly? (3 answers) Closed 6 years ago . I'm working with a nullable DateTime object and ran into some strange behavior. Here's a sample function: public DateTime? Weird() { DateTime check = DateTime.Now; DateTime? dt; if (check == DateTime.MinValue) dt = null; else dt = Viewer.ActiveThroughUTC.ToLocalTime(); //this line