在下面的代码中,无论我如何尝试,当我如图所示放置断点时,名称 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/