Can DateTime be assigned null ?

 Posted by Ddd on 2/11/2011 | Category: C# Interview questions | Views: 3223 | Points: 40
Answer:

Yes we can assign null to a variable of DateTime datatype

For ex :
.Consider this snippet

class A

{
static void Main()
{
DateTime? a=null;
Console.WriteLine("value"+"---"+a);
}
}


//Compile it and execute:

//Explanation:
//DateTime is a nullable data type(it is a value type) whose variable can be assigned null values when declared with ? sign.
In the output, we shall see the string value concatenated with blank string


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response