I am reading a .NET book, and in one of the code examples there is a class definition with this field:
private DateTime? startdate
What does DateTime? mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Since
DateTimeis astruct, not aclass, you get aDateTimeobject, not a reference, when you declare a field or variable of that type.And, in the same way as an
intcannot benull, so thisDateTimeobject can never benull, because it’s not a reference.Adding the question mark turns it into a nullable type, which means that either it is a
DateTimeobject, or it isnull.DateTime?is syntactic sugar forNullable<DateTime>, whereNullableis itself astruct.