Datetime first? Type

Source: Internet
Author: User

Inadvertently on the firstProgram-Datetime? , (I don't know if you have never used it again, but I met it for the first time). I found out the information later.It is a new feature of C #2.0,It can be a null value. I do not know if this explanation is correct. If there is a mistake, please correct it. ^_^! The following is the code from msdn:

Using System;

Class Sample
{
Public   Static   Void Main ()
{
Datetime ? Mynow;
// Assign the current date and time to mynow then display its value.
Mynow = Datetime. now;
Display (mynow, " 1) " );
// Assign null (nothing in Visual Basic) to mynow then display its value.
Mynow =   Null ;
Display (mynow, " 2) " );
}
// Display the date and time.
Public Static Void Display (datetime ? Displaydatetime, String Title)
{
// If a value is defined for the displaydatetime argument, display its value; otherwise,
// Display that no value is defined.
Console. Write (title );
If (Displaydatetime. hasvalue =   True )
Console. writeline ( " The date and time is {0: f }. " , Displaydatetime. value );
Else
Console. writeline ( " The date and time is not defined. " );
}
}

/*
This code example produces the following results:

1) The date and time is Tuesday, 4:16:06.
2) The date and time is not defined.
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.