Reputation: 404
I run the following LINQPad's C# Program twice:
void Main()
{
new Bar();
}
class Bar
{
static DateTime staticInitTime = DateTime.Now;
DateTime initTime = DateTime.Now;
public Bar()
{
staticInitTime.Dump("staticInitTime");
initTime.Dump("initTime");
}
}
and while I see no problems with the results of the first run:
staticInitTime
3/4/2017 11:45:28 PM
initTime
3/4/2017 11:45:28 PM
I can't understanding the results of the second run, just a few seconds after the first:
staticInitTime
3/4/2017 11:45:28 PM
initTime
3/4/2017 11:45:40 PM
Specifically: why staticInitTime keeps it's value between the runs? Only when I re-build the code, the value of staticInitTime gets initialized, but then only for the first run.
Upvotes: 1
Views: 101
Reputation: 109255
That's because Linqpad is smart. By default, it doesn't build a new AppDomain each time you run your query. So any static initialization will be preserved until you rebuild. You can change this behavior in the advanced preferences:
By the way, totally off topic: Linqpad rocks!
Upvotes: 2