Hi Guys
NP90 DateTime
In this program due to time lag 2nd output must have different time but it is producing the same as 1st one. I don’t why, anyone knows please explain the reason.
Thank you
namespace DateTime
{
using System;
public class DateTimeNow
{
static public void
{
object x;
x = DateTime.Now;
Console.WriteLine("{0}", x);
// Inject a time lag to get unique times.
System.Threading.Thread.Sleep(2000);
Console.WriteLine("{0}", x);
}
}
}
/*
3/25/2008 4:11:17 PM
3/25/2008 4:11:17 PM
*/
Posted Mar 26, 2008, 6:53 AM
Thank you for your explanation, Alan.
AlanPosted Mar 25, 2008, 8:05 PM
Following the delay, 'x' hasn't been reset to the new datetime and is therefore still showing the same time as before.
DateTime.Now just gives a snapshot of the time when it is called.