Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3841408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:38:58+00:00 2026-05-19T15:38:58+00:00

Possible Duplicate: Type result with conditional operator in C# I was just working on

  • 0

Possible Duplicate:
Type result with conditional operator in C#

I was just working on an a pop-up for modifying a user, when I ran into the following issue while attempting to modify the user’s Date of Death :

In this scenario, the property Death for the user is a DateTime? (Nullable Date Time).

user.Death = (model.Death != null) ? DateTime.Parse(model.Death) : null;

So I figured that I would be able to simply check if the value contained in the model (model.Death is a string) contained a value, I would set the date that value, otherwise I would set it to null, as demonstrated above.

However, I was unable to use this syntax, as it would not allow me to explicitly set user.Death to null, using the ternary operator, although user.Death = null worked just fine.

Solution used :

Replaced : null with : new Nullable<DateTime>()

I guess I am just wondering, why was I unable to explicitly set a Nullable DateTime property to null using a ternary operator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:38:58+00:00Added an answer on May 19, 2026 at 3:38 pm

    This doesn’t work because the compiler will not insert an implicit conversion on both sides at once.

    You want the compiler to convert a DateTime value to DateTime? on one side, and null to DateTime? on the other side.
    This cannot happen.

    If you explicitly convert either half to DateTime?, the other half will implicitly convert too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Type result with Ternary operator in C# I ran into this scenario,
Possible Duplicate: Define a generic that implements the + operator I am recently working
Possible Duplicate: A way to figure out redirection URL C# Issue: If we type
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: Weird Java Boxing Recently I saw a presentation where was the following
Possible Duplicate: Get generic type of java.util.List I have a Map and I want
Possible Duplicate: Why is my return type meaningless? Hi, I'm confused about a particular
Possible Duplicate: Array of zero length I have seen such type of code :-
Possible Duplicate: Why use dynamic typing in c#? Should the new C# type 'dynamic'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.