c# - 当前上下文中不存在该名称 - grrr

标签 c# string scope runtime-error

在下面的代码中,无论我如何尝试,当我如图所示放置断点时,名称 strSide “当前上下文中不存在”。我希望 strSide 包含 rawId 中的最后一个字符,然后删除该字符,以便 rawId 的值将转换为整数。我没有收到编译器错误,但确实收到了运行时错误。

rawId的值为8429R时,剥离起作用,但我无法将R分配给strSide。

        foreach (string fieldName in Request.QueryString)
        {
                rawId = fieldName;
                String strSide = Convert.ToString(rawId[rawId.Length - 1]); <-- name does not exist
                if (!IsNumeric(rawId)) <--break point set here.
                {
                    rawId = StripRightChar(rawId);  
                }
                Qty = Request.QueryString[fieldName];
            int productId = 0;
            if (fieldName == "txtReference")
            {
                strComments = Request.QueryString[fieldName];
            }

最佳答案

该变量可能已被“优化掉”吗?它创建后不会在任何地方使用。详细信息请参阅:How to prevent C# compiler/CLR from optimizing away unused variables in DEBUG builds? .

关于c# - 当前上下文中不存在该名称 - grrr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19071005/

相关文章:

java - CodingBat sameEnds 处理字符串

javascript - Node.js 和 socket.io,客户端不共享计数器

c++ - 命名空间范围与类内范围

c# - .Net 检测应用程序启动

c# - Linq ToList() 无法触发立即执行

r - 提取带有名称的向量的单词

c - C中的共享全局变量

c# - 我得到 String was not recognized as a valid DateTime error on some strings that worked for previous rows

c# - 当我不在 for 循环中使用 ToList 方法时,为什么会失败?

python - 撇号打印为 â\x80\x99