I have this code:

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();
        }
    }
}

It compiles and runs without errors.
I have a breakpoint set at Console.ReadKey(), because I wanted to inspect the variable matches.
But I got the strange error message I put in the title of this thread.
The web wasn't clear about what it meant.

So any help is as always greatly appreciated.

Recommended Answers

All 3 Replies

Works fine for me in VS2013 Ultimate running .Net 4.5 console application.

I can access the matches variable and it contains fox as expected... odd.

Make sure you're running it in Debug mode. In Release this could have been optimised away because you're not using the variable.

commented: Great! +15

Forgot to mention I used VS2010 Professional.
@Ketsuekiame: Indeed, forgot I stood in Release mode setting in Debug solved it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.