变量在 C# 版本 x64 中不递增 [英] Variable is not incrementing in C# Release x64

查看:19
本文介绍了变量在 C# 版本 x64 中不递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释为什么这段代码在 x86 平台上执行时运行良好,为什么在 x64 上失败?

Could someone explain to me why this piece of code is doing well when I execute it on a x86 platform and why it fail on x64 ?

结果:

  • x86 调试:12345678910
  • x64 调试:12345678910
  • x86 版本:12345678910
  • x64 版本:1111111111

如果我改变了一些东西,比如删除一个未使用的变量,或者如果我在 p_lFirstId++ 之后删除无用的 for 循环,奇怪的行为就会消失.

If I change something, like removing one of the unused variables, or if I remove the useless for-loop after p_lFirstId++, the strange behavior disappear.

我发现在我的发布配置中将pdb-only"更改为full",它又可以工作了.

I found that changing "pdb-only" to "full" in my release configuration, it's work again.

如果您直接从 Visual Studio 运行代码,它也运行良好.

If you run the code directly from visual studio, it's doing well too.

这是 JIT 编译器的错误吗?

Is this a JIT Compiler bug ?

提前致谢.

class Program
{
    static void Main(string[] args)
    {
        Test(null, null, null, 0, 1);            
    }

    public static void Test(
        List<string> liste, List<string> unused1,
        string unused2, int unused3, long p_lFirstId)
    {
        liste = new List<string>();

        StringBuilder sbSql = new StringBuilder();

        for (int i = 0 ; i < 10 ; i++)
        {
            sbSql.Append(p_lFirstId);
            p_lFirstId++;                

            foreach (string sColonne in liste)
            {

            }

        }

        System.Console.WriteLine(sbSql.ToString());
    } 
}

推荐答案

这是 CLR 中的一个错误.我建议联系 Microsoft 并要求他们在下一个版本中更正此错误.

This is a bug in the CLR. I would advise contacting Microsoft and asking them to correct this bug in their next release.

这篇关于变量在 C# 版本 x64 中不递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆