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

  • SEARCH
  • Home
  • 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 9210791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:09:28+00:00 2026-06-18T01:09:28+00:00

Possible Duplicate: DateTime null value There are many built-in classes in C# that are

  • 0

Possible Duplicate:
DateTime “null” value

There are many built-in classes in C# that are not Nullable.
For example, Datetime, sometimes I would like to check if my datatime object is null or not but i am not allowed. How can you insert nullability to datetime class ?

  • 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-06-18T01:09:29+00:00Added an answer on June 18, 2026 at 1:09 am

    Sure you can make an integer, double, datetime, etc. nullable with a change on the declaration.

    DateTime? dt = null.
    

    BUT

    There are two things you need to be aware of.

    1) DateTime? and DateTime are not the same data type so, if you do something like this:

    DateTime? date1 = null;
    date1 = DateTime.Now;
    
    DateTime date2 = date1; // Wont work.
    

    The correct way of accesing the value of your nullable type is like this:

    DateTime date2 = date1.Value;
    

    2) The second BUT is that you need to ALWAYS check if there is a value before you can use it.

    DateTime? date1 = null;
    DateTime date2 = date1.Value;
    

    This will throw an exception, “Nullable object must have a value”.

    So it’s not that simple as adding the nullable operator, you need to check the property “HasValue” every time you want to use your variable:

    DateTime? date1 = DateTime.Now;
    if(date1.HasValue)
    {
        DateTime date2 = date1.Value;
    }
    

    Use nullables wisely.

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

Sidebar

Related Questions

Possible Duplicate: datetime.datetime.strptime not present in Python 2.4.1 I have a machine that has
Possible Duplicate: Conditional operator assignment with Nullable<value> types? Hi, Why this doesn't work? DateTime?
Possible Duplicate: DateTime “null” value is it possible to set datetime object to null?
Possible Duplicate: c# why cant a nullable int be assigned null as a value
Possible Duplicate: DateTime.TryParse century control C# I have a C# app that's importing data
Possible Duplicate: Is there a standard date/time format that can be passed on a
Possible Duplicate: Fetching datetime from float and vice versa in python Like many people
Possible Duplicate: Convert this string to datetime I have to convert my string value
Possible Duplicate: How can I format a nullable DateTime with ToString()? ‘No overload for
Possible Duplicate: How do you set a default value for a MySQL Datetime column?

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.