注意这段代码,在.net Framework 4.6中运行时,只能得到“按任意键。”,但可以得到“配置已更改”。在.net 5.0中,为什么?
public class Holder
{
public static int IntVal = 0;
public static DateTime DateTimeVal;
}
public class StaticDateTime
{
private static DateTime config = DateTime.Now;
public StaticDateTime()
{
}
public void configChanged()
{
DateTime d = Holder.DateTimeVal;
if (d.Ticks == 0)
{
Holder.DateTimeVal = DateTime.Now;
return;
}
if (d < config)
{
Console.WriteLine("config changed.");
}
}
}
class Program
{
static void Main(string[] args)
{
StaticDateTime sd = new StaticDateTime();
sd.configChanged();
System.Threading.Thread.Sleep(1500);
StaticDateTime sd2 = new …Run Code Online (Sandbox Code Playgroud)