Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 名称';匹配项';在当前上下文中不存在_C# - Fatal编程技术网

C# 名称';匹配项';在当前上下文中不存在

C# 名称';匹配项';在当前上下文中不存在,c#,C#,我有以下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace RegexTest { class Program { static void Main(string[] args) { string str

我有以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace RegexTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "The quick brown fox.";
            string pat = "fox";
            Regex rgx = new Regex(pat, RegexOptions.IgnoreCase);
            Match matches = rgx.Match(str);
            Console.ReadKey();
        }
    }
}
它编译和运行时没有错误。 我在Console.ReadKey()上设置了一个断点,因为我想检查变量匹配情况。 但是我收到了一条奇怪的错误信息,我把它放在了这个帖子的标题里。
网络不清楚它的含义。

这个变量没有使用,所以它被优化了。添加以下内容作为临时解决方案:

int x = matches.GetHashCode();

或者,您可以暂时关闭优化,或在调试模式下编译。

如果已打开
优化代码
,则变量
匹配
将被优化掉。如果您当前的构建配置文件是
RELEASE
,则通常会出现这种情况。将其更改为“调试”,则不使用代码优化,您可以访问所需的变量。

您可以取消选中“解决方案属性”中的“优化代码”选项

Solution Properties > Build > Optimized Code

我相信这超出了范围。@HarveySpecter断点在
控制台上。ReadKey
所以它在范围内。你也可以打印
匹配的值,比如:
if(matches.Success){Console.WriteLine(matches.value);}
我不会这样做,也不建议它这样做,对于当前显示的配置,即
Release
@xxMUROxx,我建议您在打开Release模式的情况下解决此问题