当在Visual Studio中运行发行版并在Visual Studio之外运行发行版时,以下代码给出不同的输出。我使用的是Visual Studio 2008,目标是.NET 3.5。我也尝试过.NET 3.5 SP1。
在Visual Studio外部运行时,应该启动JIT。或者(a)我缺少的C#发生了一些微妙的变化,或者(b)JIT实际上是错误的。我怀疑JIT会出错,但是我没有其他机会...
在Visual Studio中运行时的输出:
    0 0,
    0 1,
    1 0,
    1 1,
在Visual Studio外部运行发行版时的输出:
    0 2,
    0 2,
    1 2,
    1 2,
是什么原因?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
    struct IntVec
    {
        public int x;
        public int y;
    }
    interface IDoSomething
    {
        void Do(IntVec o);
    }
    class DoSomething : IDoSomething
    {
        public void Do(IntVec o)
        {
            Console.WriteLine(o.x.ToString() + " " + o.y.ToString()+",");
        }
    }
    class Program
    {
        static void Test(IDoSomething oDoesSomething)
        {
            IntVec oVec = new IntVec();
            for (oVec.x = 0; oVec.x < 2; oVec.x++)
            {
                for (oVec.y = 0; oVec.y < 2; oVec.y++)
                {
                    oDoesSomething.Do(oVec);
                }
            }
        }
        static void Main(string[] args)
        {
            Test(new DoSomething());
            Console.ReadLine();
        }
    }
}
                
                8
              
                  是的-那怎么做:在.Net JIT等必不可少的东西中发现严重的错误-恭喜!
                
                
                  
                    —
                    Andras Zoltan 2010年
                    
                  
                
              
                  这似乎在我于12月9日在x86上构建4.0框架时得到了再现。我将其传递给抖动团队。谢谢!
                
                
                  
                    —
                    埃里克·利珀特
                    
                  
                
              
                  这是实际上值得一枚金牌的极少数问题之一。
                
                
                  
                    —
                    Mehrdad Afshari 2010年
                    
                  
                
              
                  我们大家都对此问题感兴趣,这一事实表明,我们并不希望 .NET JIT中的错误,也不会是Microsoft的出色表现。
                
                
                  
                    —
                    伊恩·林罗斯
                    
                  
                
              
                  我们都在等待微软的急切答复...
                
                
                  
                    —
                    Talha 2012年