Open Close Braces checking
<p>I am checking open brace and close brace. assume this is my input </p>

<blockquote>
  <p>{xyz{njdjd{lkdf}fj}jf} </p>
</blockquote>

<p>when I compile that input open brace and close braces want to separate and stored in list for that I used following code </p>

<pre><code>`List&lt;Match&gt; open=new List&lt;Match&gt;();
        List&lt;Match&gt; close = new List&lt;Match&gt;();

        MatchCollection openbrace = Regex.Matches(MELEdtior, "{");
        foreach(Match o in openbrace)
        {
            open.Add(o);
        }
        MatchCollection closebrace = Regex.Matches(MELEdtior, "}");
        foreach(Match c in closebrace)
        {
            close.Add(c);
        }
</code></pre>

<p>that's worked perfectly and I got two separate list with open and close brace.</p>

<p>Now I want compare both the list and pair the open and close brace. if any one open or close missed that pair means wants to show the error. for that I used for each loop. what I am facing means one open brace that check all close brace. but I want to check open brace with one close brace. </p>

<pre><code> if(open.Count==close.Count)
       {
        foreach(var openi in open)
        {
            foreach(var closei in close)
            {
               if( openi != closei)
               {

               }
               else { return "failed"; }
            }
        }

        }
        else{return "count failed";}

        return "";
</code></pre>

<p>what is wrong?</p>