小编Mik*_*ike的帖子

.net 5.0 VS .net Framework 4.6 不同的行为

注意这段代码,在.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)

c# .net-framework-version .net-5

5
推荐指数
1
解决办法
170
查看次数

标签 统计

.net-5 ×1

.net-framework-version ×1

c# ×1