以下代码在 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();
}
}
}